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,121 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
|
3
|
+
Portions Copyright (C) 2009-2011 David Anderson. All Rights Reserved.
|
4
|
+
|
5
|
+
This program is free software; you can redistribute it and/or modify it
|
6
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
7
|
+
as published by the Free Software Foundation.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it would be useful, but
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
Further, this software is distributed without any warranty that it is
|
14
|
+
free of the rightful claim of any third person regarding infringement
|
15
|
+
or the like. Any license provided herein, whether implied or
|
16
|
+
otherwise, applies only to this software file. Patent licenses, if
|
17
|
+
any, provided herein do not apply to combinations of this program with
|
18
|
+
other software, or any other product whatsoever.
|
19
|
+
|
20
|
+
You should have received a copy of the GNU Lesser General Public
|
21
|
+
License along with this program; if not, write the Free Software
|
22
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
23
|
+
USA.
|
24
|
+
|
25
|
+
*/
|
26
|
+
|
27
|
+
#include "config.h"
|
28
|
+
#include "dwarf_incl.h"
|
29
|
+
#include <stdio.h>
|
30
|
+
#include "dwarf_types.h"
|
31
|
+
#include "dwarf_global.h"
|
32
|
+
|
33
|
+
int
|
34
|
+
dwarf_get_types(Dwarf_Debug dbg,
|
35
|
+
Dwarf_Type ** types,
|
36
|
+
Dwarf_Signed * ret_type_count, Dwarf_Error * error)
|
37
|
+
{
|
38
|
+
int res = _dwarf_load_section(dbg, &dbg->de_debug_typenames,error);
|
39
|
+
if (res != DW_DLV_OK) {
|
40
|
+
return res;
|
41
|
+
}
|
42
|
+
if (!dbg->de_debug_typenames.dss_size) {
|
43
|
+
return (DW_DLV_NO_ENTRY);
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
return _dwarf_internal_get_pubnames_like_data(dbg,
|
48
|
+
dbg->de_debug_typenames.dss_data,
|
49
|
+
dbg->de_debug_typenames.dss_size,
|
50
|
+
(Dwarf_Global **) types, /* type punning, Dwarf_Type is
|
51
|
+
never a completed type */
|
52
|
+
ret_type_count,
|
53
|
+
error,
|
54
|
+
DW_DLA_TYPENAME_CONTEXT,
|
55
|
+
DW_DLA_TYPENAME,
|
56
|
+
DW_DLE_DEBUG_TYPENAMES_LENGTH_BAD,
|
57
|
+
DW_DLE_DEBUG_TYPENAMES_VERSION_ERROR);
|
58
|
+
}
|
59
|
+
|
60
|
+
/* Deallocating fully requires deallocating the list
|
61
|
+
and all entries. But some internal data is
|
62
|
+
not exposed, so we need a function with internal knowledge. */
|
63
|
+
|
64
|
+
void
|
65
|
+
dwarf_types_dealloc(Dwarf_Debug dbg, Dwarf_Type * dwgl,
|
66
|
+
Dwarf_Signed count)
|
67
|
+
{
|
68
|
+
_dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
|
69
|
+
count,
|
70
|
+
DW_DLA_TYPENAME_CONTEXT,
|
71
|
+
DW_DLA_TYPENAME, DW_DLA_LIST);
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
int
|
77
|
+
dwarf_typename(Dwarf_Type type_in, char **ret_name, Dwarf_Error * error)
|
78
|
+
{
|
79
|
+
Dwarf_Global type = (Dwarf_Global) type_in;
|
80
|
+
|
81
|
+
if (type == NULL) {
|
82
|
+
_dwarf_error(NULL, error, DW_DLE_TYPE_NULL);
|
83
|
+
return (DW_DLV_ERROR);
|
84
|
+
}
|
85
|
+
|
86
|
+
*ret_name = (char *) (type->gl_name);
|
87
|
+
return DW_DLV_OK;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
int
|
92
|
+
dwarf_type_die_offset(Dwarf_Type type_in,
|
93
|
+
Dwarf_Off * ret_offset, Dwarf_Error * error)
|
94
|
+
{
|
95
|
+
Dwarf_Global type = (Dwarf_Global) type_in;
|
96
|
+
|
97
|
+
return dwarf_global_die_offset(type, ret_offset, error);
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
int
|
102
|
+
dwarf_type_cu_offset(Dwarf_Type type_in,
|
103
|
+
Dwarf_Off * ret_offset, Dwarf_Error * error)
|
104
|
+
{
|
105
|
+
Dwarf_Global type = (Dwarf_Global) type_in;
|
106
|
+
|
107
|
+
return dwarf_global_cu_offset(type, ret_offset, error);
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
int
|
112
|
+
dwarf_type_name_offsets(Dwarf_Type type_in,
|
113
|
+
char **returned_name,
|
114
|
+
Dwarf_Off * die_offset,
|
115
|
+
Dwarf_Off * cu_die_offset, Dwarf_Error * error)
|
116
|
+
{
|
117
|
+
Dwarf_Global type = (Dwarf_Global) type_in;
|
118
|
+
return dwarf_global_name_offsets(type,
|
119
|
+
returned_name,
|
120
|
+
die_offset, cu_die_offset, error);
|
121
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved.
|
4
|
+
|
5
|
+
This program is free software; you can redistribute it and/or modify it
|
6
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
7
|
+
as published by the Free Software Foundation.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it would be useful, but
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
12
|
+
|
13
|
+
Further, this software is distributed without any warranty that it is
|
14
|
+
free of the rightful claim of any third person regarding infringement
|
15
|
+
or the like. Any license provided herein, whether implied or
|
16
|
+
otherwise, applies only to this software file. Patent licenses, if
|
17
|
+
any, provided herein do not apply to combinations of this program with
|
18
|
+
other software, or any other product whatsoever.
|
19
|
+
|
20
|
+
You should have received a copy of the GNU Lesser General Public
|
21
|
+
License along with this program; if not, write the Free Software
|
22
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
23
|
+
USA.
|
24
|
+
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
typedef struct Dwarf_Type_Context_s *Dwarf_Type_Context;
|
31
|
+
|
32
|
+
/* type never completed see dwarf_global.h */
|
@@ -0,0 +1,913 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
|
3
|
+
Portions Copyright (C) 2007-2012 David Anderson. All Rights Reserved.
|
4
|
+
Portions Copyright 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 <stdio.h>
|
31
|
+
#include <stdarg.h>
|
32
|
+
#include <stdlib.h> /* For free() */
|
33
|
+
#include "dwarf_die_deliv.h"
|
34
|
+
#include "pro_encode_nm.h"
|
35
|
+
|
36
|
+
|
37
|
+
#define MINBUFLEN 1000
|
38
|
+
#define TRUE 1
|
39
|
+
#define FALSE 0
|
40
|
+
|
41
|
+
Dwarf_Bool
|
42
|
+
_dwarf_file_has_debug_fission_cu_index(Dwarf_Debug dbg)
|
43
|
+
{
|
44
|
+
if(!dbg) {
|
45
|
+
return FALSE;
|
46
|
+
}
|
47
|
+
if (dbg->de_cu_hashindex_data) {
|
48
|
+
return TRUE;
|
49
|
+
}
|
50
|
+
return FALSE;
|
51
|
+
}
|
52
|
+
Dwarf_Bool
|
53
|
+
_dwarf_file_has_debug_fission_tu_index(Dwarf_Debug dbg)
|
54
|
+
{
|
55
|
+
if(!dbg) {
|
56
|
+
return FALSE;
|
57
|
+
}
|
58
|
+
if (dbg->de_tu_hashindex_data ) {
|
59
|
+
return TRUE;
|
60
|
+
}
|
61
|
+
return FALSE;
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
Dwarf_Bool
|
66
|
+
_dwarf_file_has_debug_fission_index(Dwarf_Debug dbg)
|
67
|
+
{
|
68
|
+
if(!dbg) {
|
69
|
+
return FALSE;
|
70
|
+
}
|
71
|
+
if (dbg->de_cu_hashindex_data ||
|
72
|
+
dbg->de_tu_hashindex_data) {
|
73
|
+
return 1;
|
74
|
+
}
|
75
|
+
return FALSE;
|
76
|
+
}
|
77
|
+
|
78
|
+
/* Given a form, and a pointer to the bytes encoding
|
79
|
+
a value of that form, val_ptr, this function returns
|
80
|
+
the length, in bytes, of a value of that form.
|
81
|
+
When using this function, check for a return of 0
|
82
|
+
a recursive DW_FORM_INDIRECT value. */
|
83
|
+
int
|
84
|
+
_dwarf_get_size_of_val(Dwarf_Debug dbg,
|
85
|
+
Dwarf_Unsigned form,
|
86
|
+
Dwarf_Half cu_version,
|
87
|
+
Dwarf_Half address_size,
|
88
|
+
Dwarf_Small * val_ptr,
|
89
|
+
int v_length_size,
|
90
|
+
Dwarf_Unsigned *size_out,
|
91
|
+
Dwarf_Error*error)
|
92
|
+
{
|
93
|
+
Dwarf_Unsigned length = 0;
|
94
|
+
Dwarf_Word leb128_length = 0;
|
95
|
+
Dwarf_Unsigned form_indirect = 0;
|
96
|
+
Dwarf_Unsigned ret_value = 0;
|
97
|
+
|
98
|
+
switch (form) {
|
99
|
+
|
100
|
+
/* When we encounter a FORM here that
|
101
|
+
we know about but forgot to enter here,
|
102
|
+
we had better not just continue.
|
103
|
+
Usually means we forgot to update this function
|
104
|
+
when implementing form handling of a new FORM.
|
105
|
+
Disaster results from using a bogus value,
|
106
|
+
so generate error. */
|
107
|
+
default:
|
108
|
+
_dwarf_error(dbg,error,DW_DLE_DEBUG_FORM_HANDLING_INCOMPLETE);
|
109
|
+
return DW_DLV_ERROR;
|
110
|
+
|
111
|
+
|
112
|
+
case 0: return 0;
|
113
|
+
case DW_FORM_GNU_ref_alt:
|
114
|
+
case DW_FORM_GNU_strp_alt:
|
115
|
+
case DW_FORM_strp_sup:
|
116
|
+
*size_out = v_length_size;
|
117
|
+
return DW_DLV_OK;
|
118
|
+
|
119
|
+
case DW_FORM_addr:
|
120
|
+
if (address_size) {
|
121
|
+
*size_out = address_size;
|
122
|
+
} else {
|
123
|
+
/* This should never happen, address_size should be set. */
|
124
|
+
*size_out = dbg->de_pointer_size;
|
125
|
+
}
|
126
|
+
return DW_DLV_OK;
|
127
|
+
case DW_FORM_ref_sig8:
|
128
|
+
*size_out = 8;
|
129
|
+
/* sizeof Dwarf_Sig8 */
|
130
|
+
return DW_DLV_OK;
|
131
|
+
|
132
|
+
/* DWARF2 was wrong on the size of the attribute for
|
133
|
+
DW_FORM_ref_addr. We assume compilers are using the
|
134
|
+
corrected DWARF3 text (for 32bit pointer target objects pointer and
|
135
|
+
offsets are the same size anyway).
|
136
|
+
It is clear (as of 2014) that for 64bit folks used
|
137
|
+
the V2 spec in the way V2 was
|
138
|
+
written, so the ref_addr has to account for that.*/
|
139
|
+
case DW_FORM_ref_addr:
|
140
|
+
if (cu_version == DW_CU_VERSION2) {
|
141
|
+
*size_out = address_size;
|
142
|
+
} else {
|
143
|
+
*size_out = v_length_size;
|
144
|
+
}
|
145
|
+
return DW_DLV_OK;
|
146
|
+
|
147
|
+
case DW_FORM_block1:
|
148
|
+
*size_out = *(Dwarf_Small *) val_ptr + 1;
|
149
|
+
return DW_DLV_OK;
|
150
|
+
|
151
|
+
case DW_FORM_block2:
|
152
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
|
153
|
+
val_ptr, sizeof(Dwarf_Half));
|
154
|
+
*size_out = ret_value + sizeof(Dwarf_Half);
|
155
|
+
return DW_DLV_OK;
|
156
|
+
|
157
|
+
case DW_FORM_block4:
|
158
|
+
READ_UNALIGNED(dbg, ret_value, Dwarf_Unsigned,
|
159
|
+
val_ptr, sizeof(Dwarf_ufixed));
|
160
|
+
*size_out = ret_value + sizeof(Dwarf_ufixed);
|
161
|
+
return DW_DLV_OK;
|
162
|
+
|
163
|
+
case DW_FORM_data1:
|
164
|
+
*size_out = 1;
|
165
|
+
return DW_DLV_OK;
|
166
|
+
|
167
|
+
case DW_FORM_data2:
|
168
|
+
*size_out = 2;
|
169
|
+
return DW_DLV_OK;
|
170
|
+
|
171
|
+
case DW_FORM_data4:
|
172
|
+
*size_out = 4;
|
173
|
+
return DW_DLV_OK;
|
174
|
+
|
175
|
+
case DW_FORM_data8:
|
176
|
+
*size_out = 8;
|
177
|
+
return DW_DLV_OK;
|
178
|
+
|
179
|
+
case DW_FORM_string:
|
180
|
+
*size_out = strlen((char *) val_ptr) + 1;
|
181
|
+
return DW_DLV_OK;
|
182
|
+
|
183
|
+
case DW_FORM_block:
|
184
|
+
case DW_FORM_exprloc:
|
185
|
+
length = _dwarf_decode_u_leb128(val_ptr, &leb128_length);
|
186
|
+
*size_out = length + leb128_length;
|
187
|
+
return DW_DLV_OK;
|
188
|
+
|
189
|
+
case DW_FORM_flag_present:
|
190
|
+
*size_out = 0;
|
191
|
+
return DW_DLV_OK;
|
192
|
+
|
193
|
+
case DW_FORM_flag:
|
194
|
+
*size_out = 1;
|
195
|
+
return DW_DLV_OK;
|
196
|
+
|
197
|
+
case DW_FORM_sec_offset:
|
198
|
+
/* If 32bit dwarf, is 4. Else is 64bit dwarf and is 8. */
|
199
|
+
*size_out = v_length_size;
|
200
|
+
return DW_DLV_OK;
|
201
|
+
|
202
|
+
case DW_FORM_ref_udata:
|
203
|
+
/* Discard the decoded value, we just want the length
|
204
|
+
of the value. */
|
205
|
+
_dwarf_decode_u_leb128(val_ptr, &leb128_length);
|
206
|
+
*size_out = leb128_length;
|
207
|
+
return DW_DLV_OK;
|
208
|
+
|
209
|
+
case DW_FORM_indirect:
|
210
|
+
{
|
211
|
+
Dwarf_Word indir_len = 0;
|
212
|
+
int res = 0;
|
213
|
+
Dwarf_Unsigned real_form_len = 0;
|
214
|
+
|
215
|
+
form_indirect = _dwarf_decode_u_leb128(val_ptr, &indir_len);
|
216
|
+
if (form_indirect == DW_FORM_indirect) {
|
217
|
+
/* We are in big trouble: The true form
|
218
|
+
of DW_FORM_indirect is
|
219
|
+
DW_FORM_indirect? Nonsense. Should
|
220
|
+
never happen. */
|
221
|
+
_dwarf_error(dbg,error,DW_DLE_NESTED_FORM_INDIRECT_ERROR);
|
222
|
+
return DW_DLV_ERROR;
|
223
|
+
}
|
224
|
+
res = _dwarf_get_size_of_val(dbg,
|
225
|
+
form_indirect,
|
226
|
+
cu_version,
|
227
|
+
address_size,
|
228
|
+
val_ptr + indir_len,
|
229
|
+
v_length_size,
|
230
|
+
&real_form_len,
|
231
|
+
error);
|
232
|
+
if(res != DW_DLV_OK) {
|
233
|
+
return res;
|
234
|
+
}
|
235
|
+
*size_out = indir_len + real_form_len;
|
236
|
+
return DW_DLV_OK;
|
237
|
+
}
|
238
|
+
|
239
|
+
case DW_FORM_ref1:
|
240
|
+
*size_out = 1;
|
241
|
+
return DW_DLV_OK;
|
242
|
+
|
243
|
+
case DW_FORM_ref2:
|
244
|
+
*size_out = 2;
|
245
|
+
return DW_DLV_OK;
|
246
|
+
|
247
|
+
case DW_FORM_ref4:
|
248
|
+
*size_out = 4;
|
249
|
+
return DW_DLV_OK;
|
250
|
+
|
251
|
+
case DW_FORM_ref8:
|
252
|
+
*size_out = 8;
|
253
|
+
return DW_DLV_OK;
|
254
|
+
|
255
|
+
case DW_FORM_sdata:
|
256
|
+
/* Discard the decoded value, we just want the length
|
257
|
+
of the value. */
|
258
|
+
_dwarf_decode_s_leb128(val_ptr, &leb128_length);
|
259
|
+
*size_out = (leb128_length);
|
260
|
+
return DW_DLV_OK;
|
261
|
+
|
262
|
+
|
263
|
+
case DW_FORM_addrx:
|
264
|
+
case DW_FORM_GNU_addr_index:
|
265
|
+
case DW_FORM_strx:
|
266
|
+
case DW_FORM_GNU_str_index:
|
267
|
+
_dwarf_decode_u_leb128(val_ptr, &leb128_length);
|
268
|
+
*size_out = leb128_length;
|
269
|
+
return DW_DLV_OK;
|
270
|
+
|
271
|
+
case DW_FORM_strp:
|
272
|
+
*size_out = v_length_size;
|
273
|
+
return DW_DLV_OK;
|
274
|
+
|
275
|
+
case DW_FORM_udata:
|
276
|
+
/* Discard the decoded value, we just want the length
|
277
|
+
of the value. */
|
278
|
+
_dwarf_decode_u_leb128(val_ptr, &leb128_length);
|
279
|
+
*size_out = leb128_length;
|
280
|
+
return DW_DLV_OK;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
/* We allow an arbitrary number of HT_MULTIPLE entries
|
285
|
+
before resizing. It seems up to 20 or 30
|
286
|
+
would work nearly as well.
|
287
|
+
We could have a different resize multiple than 'resize now'
|
288
|
+
test multiple, but for now we don't do that. */
|
289
|
+
#define HT_MULTIPLE 8
|
290
|
+
|
291
|
+
/* Copy the old entries, updating each to be in
|
292
|
+
a new list. Don't delete anything. Leave the
|
293
|
+
htin with stale data. */
|
294
|
+
static void
|
295
|
+
copy_abbrev_table_to_new_table(Dwarf_Hash_Table htin,
|
296
|
+
Dwarf_Hash_Table htout)
|
297
|
+
{
|
298
|
+
Dwarf_Hash_Table_Entry entry_in = htin->tb_entries;
|
299
|
+
unsigned entry_in_count = htin->tb_table_entry_count;
|
300
|
+
Dwarf_Hash_Table_Entry entry_out = htout->tb_entries;
|
301
|
+
unsigned entry_out_count = htout->tb_table_entry_count;
|
302
|
+
unsigned k = 0;
|
303
|
+
for (; k < entry_in_count; ++k,++entry_in) {
|
304
|
+
Dwarf_Abbrev_List listent = entry_in->at_head;
|
305
|
+
Dwarf_Abbrev_List nextlistent = 0;
|
306
|
+
|
307
|
+
for (; listent ; listent = nextlistent) {
|
308
|
+
unsigned newtmp = listent->ab_code;
|
309
|
+
unsigned newhash = newtmp%entry_out_count;
|
310
|
+
Dwarf_Hash_Table_Entry e;
|
311
|
+
nextlistent = listent->ab_next;
|
312
|
+
e = entry_out+newhash;
|
313
|
+
/* Move_entry_to_new_hash. This reverses the
|
314
|
+
order of the entries, effectively, but
|
315
|
+
that does not seem significant. */
|
316
|
+
listent->ab_next = e->at_head;
|
317
|
+
e->at_head = listent;
|
318
|
+
|
319
|
+
htout->tb_total_abbrev_count++;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
/* This function returns a pointer to a Dwarf_Abbrev_List_s
|
325
|
+
struct for the abbrev with the given code. It puts the
|
326
|
+
struct on the appropriate hash table. It also adds all
|
327
|
+
the abbrev between the last abbrev added and this one to
|
328
|
+
the hash table. In other words, the .debug_abbrev section
|
329
|
+
is scanned sequentially from the top for an abbrev with
|
330
|
+
the given code. All intervening abbrevs are also put
|
331
|
+
into the hash table.
|
332
|
+
|
333
|
+
This function hashes the given code, and checks the chain
|
334
|
+
at that hash table entry to see if a Dwarf_Abbrev_List_s
|
335
|
+
with the given code exists. If yes, it returns a pointer
|
336
|
+
to that struct. Otherwise, it scans the .debug_abbrev
|
337
|
+
section from the last byte scanned for that CU till either
|
338
|
+
an abbrev with the given code is found, or an abbrev code
|
339
|
+
of 0 is read. It puts Dwarf_Abbrev_List_s entries for all
|
340
|
+
abbrev's read till that point into the hash table. The
|
341
|
+
hash table contains both a head pointer and a tail pointer
|
342
|
+
for each entry.
|
343
|
+
|
344
|
+
While the lists can move and entries can be moved between
|
345
|
+
lists on reallocation, any given Dwarf_Abbrev_list entry
|
346
|
+
never moves once allocated, so the pointer is safe to return.
|
347
|
+
|
348
|
+
Returns NULL on error. */
|
349
|
+
Dwarf_Abbrev_List
|
350
|
+
_dwarf_get_abbrev_for_code(Dwarf_CU_Context cu_context, Dwarf_Unsigned code)
|
351
|
+
{
|
352
|
+
Dwarf_Debug dbg = cu_context->cc_dbg;
|
353
|
+
Dwarf_Hash_Table hash_table_base = cu_context->cc_abbrev_hash_table;
|
354
|
+
Dwarf_Hash_Table_Entry entry_base = 0;
|
355
|
+
Dwarf_Hash_Table_Entry entry_cur = 0;
|
356
|
+
Dwarf_Word hash_num = 0;
|
357
|
+
Dwarf_Unsigned abbrev_code = 0;
|
358
|
+
Dwarf_Unsigned abbrev_tag = 0;
|
359
|
+
Dwarf_Unsigned attr_name = 0;
|
360
|
+
Dwarf_Unsigned attr_form = 0;
|
361
|
+
|
362
|
+
Dwarf_Abbrev_List hash_abbrev_entry = 0;
|
363
|
+
|
364
|
+
Dwarf_Abbrev_List inner_list_entry = 0;
|
365
|
+
Dwarf_Hash_Table_Entry inner_hash_entry = 0;
|
366
|
+
|
367
|
+
Dwarf_Byte_Ptr abbrev_ptr = 0;
|
368
|
+
Dwarf_Byte_Ptr end_abbrev_ptr = 0;
|
369
|
+
unsigned hashable_val = 0;
|
370
|
+
|
371
|
+
if (!hash_table_base->tb_entries) {
|
372
|
+
hash_table_base->tb_table_entry_count = HT_MULTIPLE;
|
373
|
+
hash_table_base->tb_total_abbrev_count= 0;
|
374
|
+
hash_table_base->tb_entries =
|
375
|
+
(struct Dwarf_Hash_Table_Entry_s *)_dwarf_get_alloc(dbg,
|
376
|
+
DW_DLA_HASH_TABLE_ENTRY,
|
377
|
+
hash_table_base->tb_table_entry_count);
|
378
|
+
if (!hash_table_base->tb_entries) {
|
379
|
+
return NULL;
|
380
|
+
}
|
381
|
+
|
382
|
+
} else if (hash_table_base->tb_total_abbrev_count >
|
383
|
+
( hash_table_base->tb_table_entry_count * HT_MULTIPLE) ) {
|
384
|
+
struct Dwarf_Hash_Table_s newht;
|
385
|
+
/* Effectively multiplies by >= HT_MULTIPLE */
|
386
|
+
newht.tb_table_entry_count = hash_table_base->tb_total_abbrev_count;
|
387
|
+
newht.tb_total_abbrev_count = 0;
|
388
|
+
newht.tb_entries =
|
389
|
+
(struct Dwarf_Hash_Table_Entry_s *)_dwarf_get_alloc(dbg,
|
390
|
+
DW_DLA_HASH_TABLE_ENTRY,
|
391
|
+
newht.tb_table_entry_count);
|
392
|
+
|
393
|
+
if (!newht.tb_entries) {
|
394
|
+
return NULL;
|
395
|
+
}
|
396
|
+
/* Copy the existing entries to the new table,
|
397
|
+
rehashing each. */
|
398
|
+
copy_abbrev_table_to_new_table(hash_table_base, &newht);
|
399
|
+
/* Dealloc only the entries hash table array, not the lists
|
400
|
+
of things pointed to by a hash table entry array. */
|
401
|
+
dwarf_dealloc(dbg, hash_table_base->tb_entries,DW_DLA_HASH_TABLE_ENTRY);
|
402
|
+
hash_table_base->tb_entries = 0;
|
403
|
+
/* Now overwrite the existing table descriptor with
|
404
|
+
the new, newly valid, contents. */
|
405
|
+
*hash_table_base = newht;
|
406
|
+
} /* Else is ok as is, add entry */
|
407
|
+
|
408
|
+
hashable_val = code;
|
409
|
+
hash_num = hashable_val %
|
410
|
+
hash_table_base->tb_table_entry_count;
|
411
|
+
entry_base = hash_table_base->tb_entries;
|
412
|
+
entry_cur = entry_base + hash_num;
|
413
|
+
|
414
|
+
/* Determine if the 'code' is the list of synonyms already. */
|
415
|
+
for (hash_abbrev_entry = entry_cur->at_head;
|
416
|
+
hash_abbrev_entry != NULL && hash_abbrev_entry->ab_code != code;
|
417
|
+
hash_abbrev_entry = hash_abbrev_entry->ab_next);
|
418
|
+
if (hash_abbrev_entry != NULL) {
|
419
|
+
/* This returns a pointer to an abbrev list entry, not
|
420
|
+
the list itself. */
|
421
|
+
return (hash_abbrev_entry);
|
422
|
+
}
|
423
|
+
|
424
|
+
if (cu_context->cc_last_abbrev_ptr) {
|
425
|
+
abbrev_ptr = cu_context->cc_last_abbrev_ptr;
|
426
|
+
end_abbrev_ptr = cu_context->cc_last_abbrev_endptr;
|
427
|
+
} else {
|
428
|
+
/* This is ok because cc_abbrev_offset includes DWP
|
429
|
+
offset if appropriate. */
|
430
|
+
abbrev_ptr = dbg->de_debug_abbrev.dss_data +
|
431
|
+
cu_context->cc_abbrev_offset;
|
432
|
+
|
433
|
+
if (cu_context->cc_dwp_offsets.pcu_type) {
|
434
|
+
/* In a DWP the abbrevs
|
435
|
+
for this context are known quite precisely. */
|
436
|
+
Dwarf_Unsigned size = 0;
|
437
|
+
/* Ignore the offset returned. Already in cc_abbrev_offset. */
|
438
|
+
_dwarf_get_dwp_extra_offset(&cu_context->cc_dwp_offsets,
|
439
|
+
DW_SECT_ABBREV,&size);
|
440
|
+
/* ASSERT: size != 0 */
|
441
|
+
end_abbrev_ptr = abbrev_ptr + size;
|
442
|
+
} else {
|
443
|
+
end_abbrev_ptr = abbrev_ptr +
|
444
|
+
dbg->de_debug_abbrev.dss_size;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
|
448
|
+
/* End of abbrev's as we are past the end entirely.
|
449
|
+
THis can happen */
|
450
|
+
if (abbrev_ptr > end_abbrev_ptr) {
|
451
|
+
return (NULL);
|
452
|
+
}
|
453
|
+
/* End of abbrev's for this cu, since abbrev code is 0. */
|
454
|
+
if (*abbrev_ptr == 0) {
|
455
|
+
return (NULL);
|
456
|
+
}
|
457
|
+
|
458
|
+
do {
|
459
|
+
unsigned new_hashable_val = 0;
|
460
|
+
DECODE_LEB128_UWORD(abbrev_ptr, abbrev_code);
|
461
|
+
DECODE_LEB128_UWORD(abbrev_ptr, abbrev_tag);
|
462
|
+
|
463
|
+
inner_list_entry = (Dwarf_Abbrev_List)
|
464
|
+
_dwarf_get_alloc(cu_context->cc_dbg, DW_DLA_ABBREV_LIST, 1);
|
465
|
+
if (inner_list_entry == NULL) {
|
466
|
+
return (NULL);
|
467
|
+
}
|
468
|
+
|
469
|
+
new_hashable_val = abbrev_code;
|
470
|
+
hash_num = new_hashable_val %
|
471
|
+
hash_table_base->tb_table_entry_count;
|
472
|
+
inner_hash_entry = entry_base + hash_num;
|
473
|
+
/* Move_entry_to_new_hash */
|
474
|
+
inner_list_entry->ab_next = inner_hash_entry->at_head;
|
475
|
+
inner_hash_entry->at_head = inner_list_entry;
|
476
|
+
|
477
|
+
hash_table_base->tb_total_abbrev_count++;
|
478
|
+
|
479
|
+
inner_list_entry->ab_code = abbrev_code;
|
480
|
+
inner_list_entry->ab_tag = abbrev_tag;
|
481
|
+
inner_list_entry->ab_has_child = *(abbrev_ptr++);
|
482
|
+
inner_list_entry->ab_abbrev_ptr = abbrev_ptr;
|
483
|
+
|
484
|
+
/* Cycle thru the abbrev content, ignoring the content except
|
485
|
+
to find the end of the content. */
|
486
|
+
do {
|
487
|
+
DECODE_LEB128_UWORD(abbrev_ptr, attr_name);
|
488
|
+
DECODE_LEB128_UWORD(abbrev_ptr, attr_form);
|
489
|
+
} while (attr_name != 0 && attr_form != 0);
|
490
|
+
|
491
|
+
/* We may have fallen off the end of content, that is not
|
492
|
+
a botch in the section, as there is no rule that the last
|
493
|
+
abbrev need have abbrev_code of 0. */
|
494
|
+
} while ((abbrev_ptr < end_abbrev_ptr) &&
|
495
|
+
*abbrev_ptr != 0 && abbrev_code != code);
|
496
|
+
|
497
|
+
cu_context->cc_last_abbrev_ptr = abbrev_ptr;
|
498
|
+
cu_context->cc_last_abbrev_endptr = end_abbrev_ptr;
|
499
|
+
return (abbrev_code == code ? inner_list_entry : NULL);
|
500
|
+
}
|
501
|
+
|
502
|
+
|
503
|
+
/*
|
504
|
+
We check that:
|
505
|
+
areaptr <= strptr.
|
506
|
+
a NUL byte (*p) exists at p < end.
|
507
|
+
and return DW_DLV_ERROR if a check fails.
|
508
|
+
|
509
|
+
de_assume_string_in_bounds
|
510
|
+
*/
|
511
|
+
int
|
512
|
+
_dwarf_check_string_valid(Dwarf_Debug dbg,void *areaptr,
|
513
|
+
void *strptr, void *areaendptr,
|
514
|
+
Dwarf_Error*error)
|
515
|
+
{
|
516
|
+
|
517
|
+
Dwarf_Small *start = areaptr;
|
518
|
+
Dwarf_Small *p = strptr;
|
519
|
+
Dwarf_Small *end = areaendptr;
|
520
|
+
if (p < start) {
|
521
|
+
_dwarf_error(dbg,error,DW_DLE_DEBUG_STR_OFFSET_BAD);
|
522
|
+
return DW_DLV_ERROR;
|
523
|
+
}
|
524
|
+
if (p >= end) {
|
525
|
+
_dwarf_error(dbg,error,DW_DLE_DEBUG_STR_OFFSET_BAD);
|
526
|
+
return DW_DLV_ERROR;
|
527
|
+
}
|
528
|
+
if (dbg->de_assume_string_in_bounds) {
|
529
|
+
/* This NOT the default. But folks can choose
|
530
|
+
to live dangerously and just assume strings ok. */
|
531
|
+
return DW_DLV_OK;
|
532
|
+
}
|
533
|
+
while (p < end) {
|
534
|
+
if (*p == 0) {
|
535
|
+
return DW_DLV_OK;
|
536
|
+
}
|
537
|
+
++p;
|
538
|
+
}
|
539
|
+
_dwarf_error(dbg,error,DW_DLE_STRING_NOT_TERMINATED);
|
540
|
+
return DW_DLV_ERROR;
|
541
|
+
}
|
542
|
+
|
543
|
+
|
544
|
+
/* Return non-zero if the start/end are not valid for the
|
545
|
+
die's section.
|
546
|
+
Return 0 if valid*/
|
547
|
+
int
|
548
|
+
_dwarf_reference_outside_section(Dwarf_Die die,
|
549
|
+
Dwarf_Small * startaddr,
|
550
|
+
Dwarf_Small * pastend)
|
551
|
+
{
|
552
|
+
Dwarf_Debug dbg = 0;
|
553
|
+
Dwarf_CU_Context contxt = 0;
|
554
|
+
struct Dwarf_Section_s *sec = 0;
|
555
|
+
|
556
|
+
contxt = die->di_cu_context;
|
557
|
+
dbg = contxt->cc_dbg;
|
558
|
+
if (die->di_is_info) {
|
559
|
+
sec = &dbg->de_debug_info;
|
560
|
+
} else {
|
561
|
+
sec = &dbg->de_debug_types;
|
562
|
+
}
|
563
|
+
if (startaddr < sec->dss_data) {
|
564
|
+
return 1;
|
565
|
+
}
|
566
|
+
if (pastend > (sec->dss_data + sec->dss_size)) {
|
567
|
+
return 1;
|
568
|
+
}
|
569
|
+
return 0;
|
570
|
+
}
|
571
|
+
|
572
|
+
|
573
|
+
/*
|
574
|
+
A byte-swapping version of memcpy
|
575
|
+
for cross-endian use.
|
576
|
+
Only 2,4,8 should be lengths passed in.
|
577
|
+
*/
|
578
|
+
void *
|
579
|
+
_dwarf_memcpy_swap_bytes(void *s1, const void *s2, size_t len)
|
580
|
+
{
|
581
|
+
void *orig_s1 = s1;
|
582
|
+
unsigned char *targ = (unsigned char *) s1;
|
583
|
+
const unsigned char *src = (const unsigned char *) s2;
|
584
|
+
|
585
|
+
if (len == 4) {
|
586
|
+
targ[3] = src[0];
|
587
|
+
targ[2] = src[1];
|
588
|
+
targ[1] = src[2];
|
589
|
+
targ[0] = src[3];
|
590
|
+
} else if (len == 8) {
|
591
|
+
targ[7] = src[0];
|
592
|
+
targ[6] = src[1];
|
593
|
+
targ[5] = src[2];
|
594
|
+
targ[4] = src[3];
|
595
|
+
targ[3] = src[4];
|
596
|
+
targ[2] = src[5];
|
597
|
+
targ[1] = src[6];
|
598
|
+
targ[0] = src[7];
|
599
|
+
} else if (len == 2) {
|
600
|
+
targ[1] = src[0];
|
601
|
+
targ[0] = src[1];
|
602
|
+
}
|
603
|
+
/* should NOT get below here: is not the intended use */
|
604
|
+
else if (len == 1) {
|
605
|
+
targ[0] = src[0];
|
606
|
+
} else {
|
607
|
+
memcpy(s1, s2, len);
|
608
|
+
}
|
609
|
+
|
610
|
+
return orig_s1;
|
611
|
+
}
|
612
|
+
|
613
|
+
|
614
|
+
/* This calculation used to be sprinkled all over.
|
615
|
+
Now brought to one place.
|
616
|
+
|
617
|
+
We try to accurately compute the size of a cu header
|
618
|
+
given a known cu header location ( an offset in .debug_info
|
619
|
+
or debug_types). */
|
620
|
+
/* ARGSUSED */
|
621
|
+
Dwarf_Unsigned
|
622
|
+
_dwarf_length_of_cu_header(Dwarf_Debug dbg, Dwarf_Unsigned offset,
|
623
|
+
Dwarf_Bool is_info)
|
624
|
+
{
|
625
|
+
int local_length_size = 0;
|
626
|
+
int local_extension_size = 0;
|
627
|
+
Dwarf_Unsigned length = 0;
|
628
|
+
Dwarf_Unsigned final_size = 0;
|
629
|
+
Dwarf_Small *cuptr =
|
630
|
+
is_info? dbg->de_debug_info.dss_data + offset:
|
631
|
+
dbg->de_debug_types.dss_data+ offset;
|
632
|
+
|
633
|
+
READ_AREA_LENGTH(dbg, length, Dwarf_Unsigned,
|
634
|
+
cuptr, local_length_size, local_extension_size);
|
635
|
+
|
636
|
+
final_size = local_extension_size + /* initial extension, if present */
|
637
|
+
local_length_size + /* Size of cu length field. */
|
638
|
+
sizeof(Dwarf_Half) + /* Size of version stamp field. */
|
639
|
+
local_length_size + /* Size of abbrev offset field. */
|
640
|
+
sizeof(Dwarf_Small); /* Size of address size field. */
|
641
|
+
|
642
|
+
if (!is_info) {
|
643
|
+
final_size +=
|
644
|
+
/* type signature size */
|
645
|
+
sizeof (Dwarf_Sig8) +
|
646
|
+
/* type offset size */
|
647
|
+
local_length_size;
|
648
|
+
}
|
649
|
+
return final_size;
|
650
|
+
}
|
651
|
+
|
652
|
+
/* Pretend we know nothing about the CU
|
653
|
+
and just roughly compute the result. */
|
654
|
+
Dwarf_Unsigned
|
655
|
+
_dwarf_length_of_cu_header_simple(Dwarf_Debug dbg,
|
656
|
+
Dwarf_Bool dinfo)
|
657
|
+
{
|
658
|
+
Dwarf_Unsigned finalsize = 0;
|
659
|
+
finalsize = dbg->de_length_size + /* Size of cu length field. */
|
660
|
+
sizeof(Dwarf_Half) + /* Size of version stamp field. */
|
661
|
+
dbg->de_length_size + /* Size of abbrev offset field. */
|
662
|
+
sizeof(Dwarf_Small); /* Size of address size field. */
|
663
|
+
if (!dinfo) {
|
664
|
+
finalsize +=
|
665
|
+
/* type signature size */
|
666
|
+
sizeof (Dwarf_Sig8) +
|
667
|
+
/* type offset size */
|
668
|
+
dbg->de_length_size;
|
669
|
+
}
|
670
|
+
return finalsize;
|
671
|
+
}
|
672
|
+
|
673
|
+
/* Now that we delay loading .debug_info, we need to do the
|
674
|
+
load in more places. So putting the load
|
675
|
+
code in one place now instead of replicating it in multiple
|
676
|
+
places. */
|
677
|
+
int
|
678
|
+
_dwarf_load_debug_info(Dwarf_Debug dbg, Dwarf_Error * error)
|
679
|
+
{
|
680
|
+
int res = DW_DLV_ERROR;
|
681
|
+
if (dbg->de_debug_info.dss_data) {
|
682
|
+
return DW_DLV_OK;
|
683
|
+
}
|
684
|
+
res = _dwarf_load_section(dbg, &dbg->de_debug_abbrev,error);
|
685
|
+
if (res != DW_DLV_OK) {
|
686
|
+
return res;
|
687
|
+
}
|
688
|
+
res = _dwarf_load_section(dbg, &dbg->de_debug_info, error);
|
689
|
+
return res;
|
690
|
+
}
|
691
|
+
int
|
692
|
+
_dwarf_load_debug_types(Dwarf_Debug dbg, Dwarf_Error * error)
|
693
|
+
{
|
694
|
+
int res = DW_DLV_ERROR;
|
695
|
+
if (dbg->de_debug_types.dss_data) {
|
696
|
+
return DW_DLV_OK;
|
697
|
+
}
|
698
|
+
res = _dwarf_load_section(dbg, &dbg->de_debug_abbrev,error);
|
699
|
+
if (res != DW_DLV_OK) {
|
700
|
+
return res;
|
701
|
+
}
|
702
|
+
res = _dwarf_load_section(dbg, &dbg->de_debug_types, error);
|
703
|
+
return res;
|
704
|
+
}
|
705
|
+
void
|
706
|
+
_dwarf_free_abbrev_hash_table_contents(Dwarf_Debug dbg,Dwarf_Hash_Table hash_table)
|
707
|
+
{
|
708
|
+
/* A Hash Table is an array with tb_table_entry_count struct
|
709
|
+
Dwarf_Hash_Table_s entries in the array. */
|
710
|
+
unsigned hashnum = 0;
|
711
|
+
for (; hashnum < hash_table->tb_table_entry_count; ++hashnum) {
|
712
|
+
struct Dwarf_Abbrev_List_s *abbrev = 0;
|
713
|
+
struct Dwarf_Abbrev_List_s *nextabbrev = 0;
|
714
|
+
struct Dwarf_Hash_Table_Entry_s *tb = &hash_table->tb_entries[hashnum];
|
715
|
+
|
716
|
+
abbrev = tb->at_head;
|
717
|
+
for (; abbrev; abbrev = nextabbrev) {
|
718
|
+
nextabbrev = abbrev->ab_next;
|
719
|
+
abbrev->ab_next = 0;
|
720
|
+
dwarf_dealloc(dbg, abbrev, DW_DLA_ABBREV_LIST);
|
721
|
+
}
|
722
|
+
tb->at_head = 0;
|
723
|
+
}
|
724
|
+
/* Frees all the entries at once: an array. */
|
725
|
+
dwarf_dealloc(dbg,hash_table->tb_entries,DW_DLA_HASH_TABLE_ENTRY);
|
726
|
+
hash_table->tb_entries = 0;
|
727
|
+
}
|
728
|
+
|
729
|
+
/*
|
730
|
+
If no die provided the size value returned might be wrong.
|
731
|
+
If different compilation units have different address sizes
|
732
|
+
this may not give the correct value in all contexts if the die
|
733
|
+
pointer is NULL.
|
734
|
+
If the Elf offset size != address_size
|
735
|
+
(for example if address_size = 4 but recorded in elf64 object)
|
736
|
+
this may not give the correct value in all contexts if the die
|
737
|
+
pointer is NULL.
|
738
|
+
If the die pointer is non-NULL (in which case it must point to
|
739
|
+
a valid DIE) this will return the correct size.
|
740
|
+
*/
|
741
|
+
int
|
742
|
+
_dwarf_get_address_size(Dwarf_Debug dbg, Dwarf_Die die)
|
743
|
+
{
|
744
|
+
Dwarf_CU_Context context = 0;
|
745
|
+
Dwarf_Half addrsize = 0;
|
746
|
+
if (!die) {
|
747
|
+
return dbg->de_pointer_size;
|
748
|
+
}
|
749
|
+
context = die->di_cu_context;
|
750
|
+
addrsize = context->cc_address_size;
|
751
|
+
return addrsize;
|
752
|
+
}
|
753
|
+
|
754
|
+
/* Encode val as an unsigned LEB128. */
|
755
|
+
int dwarf_encode_leb128(Dwarf_Unsigned val, int *nbytes,
|
756
|
+
char *space, int splen)
|
757
|
+
{
|
758
|
+
/* Encode val as an unsigned LEB128. */
|
759
|
+
return _dwarf_pro_encode_leb128_nm(val,nbytes,space,splen);
|
760
|
+
}
|
761
|
+
|
762
|
+
/* Encode val as a signed LEB128. */
|
763
|
+
int dwarf_encode_signed_leb128(Dwarf_Signed val, int *nbytes,
|
764
|
+
char *space, int splen)
|
765
|
+
{
|
766
|
+
/* Encode val as a signed LEB128. */
|
767
|
+
return _dwarf_pro_encode_signed_leb128_nm(val,nbytes,space,splen);
|
768
|
+
}
|
769
|
+
|
770
|
+
|
771
|
+
struct Dwarf_Printf_Callback_Info_s
|
772
|
+
dwarf_register_printf_callback( Dwarf_Debug dbg,
|
773
|
+
struct Dwarf_Printf_Callback_Info_s * newvalues)
|
774
|
+
{
|
775
|
+
struct Dwarf_Printf_Callback_Info_s oldval = dbg->de_printf_callback;
|
776
|
+
if (!newvalues) {
|
777
|
+
return oldval;
|
778
|
+
}
|
779
|
+
if( newvalues->dp_buffer_user_provided) {
|
780
|
+
if( oldval.dp_buffer_user_provided) {
|
781
|
+
/* User continues to control the buffer. */
|
782
|
+
dbg->de_printf_callback = *newvalues;
|
783
|
+
}else {
|
784
|
+
/* Switch from our control of buffer to user
|
785
|
+
control. */
|
786
|
+
free(oldval.dp_buffer);
|
787
|
+
oldval.dp_buffer = 0;
|
788
|
+
dbg->de_printf_callback = *newvalues;
|
789
|
+
}
|
790
|
+
} else if (oldval.dp_buffer_user_provided){
|
791
|
+
/* Switch from user control to our control */
|
792
|
+
dbg->de_printf_callback = *newvalues;
|
793
|
+
dbg->de_printf_callback.dp_buffer_len = 0;
|
794
|
+
dbg->de_printf_callback.dp_buffer= 0;
|
795
|
+
} else {
|
796
|
+
/* User does not control the buffer. */
|
797
|
+
dbg->de_printf_callback = *newvalues;
|
798
|
+
dbg->de_printf_callback.dp_buffer_len =
|
799
|
+
oldval.dp_buffer_len;
|
800
|
+
dbg->de_printf_callback.dp_buffer =
|
801
|
+
oldval.dp_buffer;
|
802
|
+
}
|
803
|
+
return oldval;
|
804
|
+
}
|
805
|
+
|
806
|
+
|
807
|
+
/* start is a minimum size, but may be zero. */
|
808
|
+
static void bufferdoublesize(struct Dwarf_Printf_Callback_Info_s *bufdata)
|
809
|
+
{
|
810
|
+
char *space = 0;
|
811
|
+
unsigned int targlen = 0;
|
812
|
+
if (bufdata->dp_buffer_len == 0) {
|
813
|
+
targlen = MINBUFLEN;
|
814
|
+
} else {
|
815
|
+
targlen = bufdata->dp_buffer_len * 2;
|
816
|
+
if (targlen < bufdata->dp_buffer_len) {
|
817
|
+
/* Overflow, we cannot do this doubling. */
|
818
|
+
return;
|
819
|
+
}
|
820
|
+
}
|
821
|
+
/* Make big enough for a trailing NUL char. */
|
822
|
+
space = (char *)malloc(targlen+1);
|
823
|
+
if (!space) {
|
824
|
+
/* Out of space, we cannot double it. */
|
825
|
+
return;
|
826
|
+
}
|
827
|
+
free(bufdata->dp_buffer);
|
828
|
+
bufdata->dp_buffer = space;
|
829
|
+
bufdata->dp_buffer_len = targlen;
|
830
|
+
return;
|
831
|
+
}
|
832
|
+
|
833
|
+
int
|
834
|
+
dwarf_printf(Dwarf_Debug dbg,
|
835
|
+
const char * format,
|
836
|
+
...)
|
837
|
+
{
|
838
|
+
va_list ap;
|
839
|
+
int maxtries = 4;
|
840
|
+
int tries = 0;
|
841
|
+
struct Dwarf_Printf_Callback_Info_s *bufdata =
|
842
|
+
&dbg->de_printf_callback;
|
843
|
+
dwarf_printf_callback_function_type func = bufdata->dp_fptr;
|
844
|
+
if (!func) {
|
845
|
+
return 0;
|
846
|
+
}
|
847
|
+
if (!bufdata->dp_buffer) {
|
848
|
+
bufferdoublesize(bufdata);
|
849
|
+
if (!bufdata->dp_buffer) {
|
850
|
+
/* Something is wrong. Possibly caller
|
851
|
+
set up callback wrong. */
|
852
|
+
return 0;
|
853
|
+
}
|
854
|
+
}
|
855
|
+
|
856
|
+
/* Here we ensure (or nearly ensure) we expand
|
857
|
+
the buffer when necessary, but not excessively
|
858
|
+
(but only if we control the buffer size). */
|
859
|
+
while (1) {
|
860
|
+
int olen = 0;
|
861
|
+
tries++;
|
862
|
+
va_start(ap,format);
|
863
|
+
olen = vsnprintf(bufdata->dp_buffer,
|
864
|
+
bufdata->dp_buffer_len, format,ap);
|
865
|
+
/* "The object ap may be passed as an argument to another
|
866
|
+
function; if that function invokes the va_arg()
|
867
|
+
macro with parameter ap, the value of ap in the calling
|
868
|
+
function is unspecified and shall be passed to the va_end()
|
869
|
+
macro prior to any further reference to ap."
|
870
|
+
Single Unix Specification. */
|
871
|
+
va_end(ap);
|
872
|
+
if (olen > -1 && (long)olen < (long)bufdata->dp_buffer_len) {
|
873
|
+
/* The caller had better copy or dispose
|
874
|
+
of the contents, as next-call will overwrite them. */
|
875
|
+
func(bufdata->dp_user_pointer,bufdata->dp_buffer);
|
876
|
+
return 0;
|
877
|
+
}
|
878
|
+
if (bufdata->dp_buffer_user_provided) {
|
879
|
+
func(bufdata->dp_user_pointer,bufdata->dp_buffer);
|
880
|
+
return 0;
|
881
|
+
}
|
882
|
+
if (tries > maxtries) {
|
883
|
+
/* we did all we could, print what we have space for. */
|
884
|
+
func(bufdata->dp_user_pointer,bufdata->dp_buffer);
|
885
|
+
return 0;
|
886
|
+
}
|
887
|
+
bufferdoublesize(bufdata);
|
888
|
+
}
|
889
|
+
/* Not reached. */
|
890
|
+
return 0;
|
891
|
+
}
|
892
|
+
|
893
|
+
/* Often errs and errt point to the same Dwarf_Error,
|
894
|
+
So exercise care. */
|
895
|
+
|
896
|
+
void
|
897
|
+
_dwarf_error_mv_s_to_t(Dwarf_Debug dbgs,Dwarf_Error *errs,
|
898
|
+
Dwarf_Debug dbgt,Dwarf_Error *errt)
|
899
|
+
{
|
900
|
+
if(dbgs == dbgt) {
|
901
|
+
if(errs != errt) {
|
902
|
+
Dwarf_Error ers = *errs;
|
903
|
+
*errs = 0;
|
904
|
+
*errt = ers;
|
905
|
+
}
|
906
|
+
} else {
|
907
|
+
int errno = dwarf_errno(*errs);
|
908
|
+
dwarf_dealloc(dbgs,*errs, DW_DLA_ERROR);
|
909
|
+
*errs = 0;
|
910
|
+
_dwarf_error(dbgt,errt, errno);
|
911
|
+
}
|
912
|
+
}
|
913
|
+
|