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,117 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2000,2004,2005 Silicon Graphics, Inc. All Rights Reserved.
|
4
|
+
Portions Copyright (C) 2011 David Anderson. All Rights Reserved.
|
5
|
+
|
6
|
+
|
7
|
+
This program is free software; you can redistribute it and/or modify it
|
8
|
+
under the terms of version 2.1 of the GNU Lesser General Public License
|
9
|
+
as published by the Free Software Foundation.
|
10
|
+
|
11
|
+
This program is distributed in the hope that it would be useful, but
|
12
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
14
|
+
|
15
|
+
Further, this software is distributed without any warranty that it is
|
16
|
+
free of the rightful claim of any third person regarding infringement
|
17
|
+
or the like. Any license provided herein, whether implied or
|
18
|
+
otherwise, applies only to this software file. Patent licenses, if
|
19
|
+
any, provided herein do not apply to combinations of this program with
|
20
|
+
other software, or any other product whatsoever.
|
21
|
+
|
22
|
+
You should have received a copy of the GNU Lesser General Public
|
23
|
+
License along with this program; if not, write the Free Software
|
24
|
+
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
|
25
|
+
USA.
|
26
|
+
|
27
|
+
*/
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
typedef struct Dwarf_Global_Context_s *Dwarf_Global_Context;
|
33
|
+
|
34
|
+
/*
|
35
|
+
This struct contains header information for a set of pubnames.
|
36
|
+
Essentially, they contain the context for a set of pubnames
|
37
|
+
belonging to a compilation-unit.
|
38
|
+
|
39
|
+
This is also used for the sgi-specific
|
40
|
+
weaknames, typenames, varnames, funcnames data:
|
41
|
+
the structs for those are incomplete and
|
42
|
+
instances of this are used instead.
|
43
|
+
|
44
|
+
Also used for DWARF3 .debug_pubtypes.
|
45
|
+
|
46
|
+
These never refer to .debug_types, only to .debug_info.
|
47
|
+
|
48
|
+
*/
|
49
|
+
struct Dwarf_Global_Context_s {
|
50
|
+
|
51
|
+
/* Length in .debug_pubnames (etc) of a set of names for a
|
52
|
+
compilation-unit. Dwarf_Word pu_length; The value is not made
|
53
|
+
available outside libdwarf and not used inside, so no need to
|
54
|
+
record it. */
|
55
|
+
|
56
|
+
/* For this context, size of a length. 4 or 8 */
|
57
|
+
unsigned char pu_length_size;
|
58
|
+
|
59
|
+
/* For this CU, size of the extension 0 except for dwarf2 extension
|
60
|
+
64bit, in which case is 4. */
|
61
|
+
unsigned char pu_extension_size;
|
62
|
+
|
63
|
+
/* Offset into .debug_info of the compilation-unit header (not DIE)
|
64
|
+
for this set of pubnames. */
|
65
|
+
Dwarf_Off pu_offset_of_cu_header;
|
66
|
+
|
67
|
+
/* Size of compilation-unit that these pubnames are in. */
|
68
|
+
Dwarf_Unsigned pu_info_length;
|
69
|
+
|
70
|
+
Dwarf_Debug pu_dbg;
|
71
|
+
};
|
72
|
+
|
73
|
+
|
74
|
+
/* This struct contains information for a single pubname. */
|
75
|
+
struct Dwarf_Global_s {
|
76
|
+
|
77
|
+
/* Offset from the start of the corresponding compilation-unit of
|
78
|
+
the DIE for the given pubname CU. */
|
79
|
+
Dwarf_Off gl_named_die_offset_within_cu;
|
80
|
+
|
81
|
+
/* Points to the given pubname. */
|
82
|
+
Dwarf_Small *gl_name;
|
83
|
+
|
84
|
+
/* Context for this pubname. */
|
85
|
+
Dwarf_Global_Context gl_context;
|
86
|
+
};
|
87
|
+
|
88
|
+
int _dwarf_internal_get_pubnames_like_data(Dwarf_Debug dbg,
|
89
|
+
Dwarf_Small *
|
90
|
+
section_data_ptr,
|
91
|
+
Dwarf_Unsigned
|
92
|
+
section_length,
|
93
|
+
Dwarf_Global ** globals,
|
94
|
+
Dwarf_Signed * return_count,
|
95
|
+
Dwarf_Error * error,
|
96
|
+
int context_code,
|
97
|
+
int global_code,
|
98
|
+
int length_err_num,
|
99
|
+
int version_err_num);
|
100
|
+
|
101
|
+
void
|
102
|
+
_dwarf_internal_globals_dealloc( Dwarf_Debug dbg, Dwarf_Global *dwgl,
|
103
|
+
Dwarf_Signed count,
|
104
|
+
int context_code,
|
105
|
+
int global_code,
|
106
|
+
int list_code);
|
107
|
+
|
108
|
+
|
109
|
+
#ifdef __sgi /* __sgi should only be defined for IRIX/MIPS. */
|
110
|
+
void _dwarf_fix_up_offset_irix(Dwarf_Debug dbg,
|
111
|
+
Dwarf_Unsigned *varp,
|
112
|
+
char *caller_site_name);
|
113
|
+
#define FIX_UP_OFFSET_IRIX_BUG(ldbg,var,name) _dwarf_fix_up_offset_irix(ldbg,&var,name)
|
114
|
+
#else /* ! __sgi */
|
115
|
+
#define FIX_UP_OFFSET_IRIX_BUG(ldbg,var,name)
|
116
|
+
#endif /* __sgi */
|
117
|
+
|
@@ -0,0 +1,228 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2010-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
|
+
/* This implements _dwarf_insert_harmless_error
|
29
|
+
and related helper functions for recording
|
30
|
+
compiler errors that need not make the input
|
31
|
+
unusable.
|
32
|
+
|
33
|
+
Applications can use dwarf_get_harmless_error_list to
|
34
|
+
find (and possibly print) a warning about such errors.
|
35
|
+
|
36
|
+
The initial error reported here is
|
37
|
+
DW_DLE_DEBUG_FRAME_LENGTH_NOT_MULTIPLE which was a
|
38
|
+
bug in a specific compiler.
|
39
|
+
|
40
|
+
It is a fixed length circular list to constrain
|
41
|
+
the space used for errors.
|
42
|
+
|
43
|
+
The assumption is that these errors are exceedingly
|
44
|
+
rare, and indicate a broken compiler (the one that
|
45
|
+
produced the object getting the error(s)).
|
46
|
+
|
47
|
+
dh_maxcount is recorded internally as 1 greater than
|
48
|
+
requested. Hiding the fact we always leave one
|
49
|
+
slot unused (at least). So a user request for
|
50
|
+
N slots really gives the user N usable slots. */
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
#include "config.h"
|
55
|
+
#include "dwarf_incl.h"
|
56
|
+
#include <stdio.h>
|
57
|
+
#include <stdlib.h>
|
58
|
+
#include "dwarf_frame.h"
|
59
|
+
#include "dwarf_harmless.h"
|
60
|
+
|
61
|
+
|
62
|
+
/* The pointers returned here through errmsg_ptrs_array
|
63
|
+
become invalidated by any call to libdwarf. Any call.
|
64
|
+
*/
|
65
|
+
int dwarf_get_harmless_error_list(Dwarf_Debug dbg,
|
66
|
+
unsigned count,
|
67
|
+
const char ** errmsg_ptrs_array,
|
68
|
+
unsigned * errs_count)
|
69
|
+
{
|
70
|
+
struct Dwarf_Harmless_s *dhp = &dbg->de_harmless_errors;
|
71
|
+
if (!dhp->dh_errors) {
|
72
|
+
dhp->dh_errs_count = 0;
|
73
|
+
return DW_DLV_NO_ENTRY;
|
74
|
+
}
|
75
|
+
if (dhp->dh_errs_count == 0) {
|
76
|
+
return DW_DLV_NO_ENTRY;
|
77
|
+
}
|
78
|
+
if (errs_count) {
|
79
|
+
*errs_count = dhp->dh_errs_count;
|
80
|
+
}
|
81
|
+
if (count) {
|
82
|
+
/* NULL terminate the array of pointers */
|
83
|
+
--count;
|
84
|
+
errmsg_ptrs_array[count] = 0;
|
85
|
+
|
86
|
+
if (dhp->dh_next_to_use != dhp->dh_first) {
|
87
|
+
unsigned i = 0;
|
88
|
+
unsigned cur = dhp->dh_first;
|
89
|
+
for (i = 0; cur != dhp->dh_next_to_use; ++i) {
|
90
|
+
if (i >= count ) {
|
91
|
+
/* All output spaces are used. */
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
errmsg_ptrs_array[i] = dhp->dh_errors[cur];
|
95
|
+
cur = (cur +1) % dhp->dh_maxcount;
|
96
|
+
}
|
97
|
+
errmsg_ptrs_array[i] = 0;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
dhp->dh_next_to_use = 0;
|
101
|
+
dhp->dh_first = 0;
|
102
|
+
dhp->dh_errs_count = 0;
|
103
|
+
return DW_DLV_OK;
|
104
|
+
}
|
105
|
+
|
106
|
+
/* strncpy does not null-terminate, this does it. */
|
107
|
+
static void
|
108
|
+
safe_strncpy(char *targ, char *src, unsigned spaceavail)
|
109
|
+
{
|
110
|
+
unsigned goodcount = spaceavail-1;
|
111
|
+
if (spaceavail < 1) {
|
112
|
+
return; /* impossible */
|
113
|
+
}
|
114
|
+
strncpy(targ,src,goodcount);
|
115
|
+
targ[goodcount] = 0;
|
116
|
+
}
|
117
|
+
|
118
|
+
/* Insertion made public is only for testing the harmless error code,
|
119
|
+
it is not necessarily useful for libdwarf client code aside
|
120
|
+
from code testing libdwarf. */
|
121
|
+
void dwarf_insert_harmless_error(Dwarf_Debug dbg,
|
122
|
+
char *newerror)
|
123
|
+
{
|
124
|
+
struct Dwarf_Harmless_s *dhp = &dbg->de_harmless_errors;
|
125
|
+
unsigned next = 0;
|
126
|
+
unsigned cur = dhp->dh_next_to_use;
|
127
|
+
char *msgspace;
|
128
|
+
if (!dhp->dh_errors) {
|
129
|
+
dhp->dh_errs_count++;
|
130
|
+
return;
|
131
|
+
}
|
132
|
+
msgspace = dhp->dh_errors[cur];
|
133
|
+
safe_strncpy(msgspace, newerror,DW_HARMLESS_ERROR_MSG_STRING_SIZE);
|
134
|
+
next = (cur+1) % dhp->dh_maxcount;
|
135
|
+
dhp->dh_errs_count++;
|
136
|
+
dhp->dh_next_to_use = next;
|
137
|
+
if (dhp->dh_next_to_use == dhp->dh_first) {
|
138
|
+
/* Array is full set full invariant. */
|
139
|
+
dhp->dh_first = (dhp->dh_first+1) % dhp->dh_maxcount;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
/* The size of the circular list of strings may be set
|
144
|
+
and reset as desired. Returns the previous size of
|
145
|
+
the list. If the list is shortened excess error entries
|
146
|
+
are simply dropped.
|
147
|
+
If the reallocation fails the list size is left unchanged.
|
148
|
+
Do not make this a long list!
|
149
|
+
|
150
|
+
Remember the maxcount we record is 1 > the user count,
|
151
|
+
so we adjust it so it looks like the user count.
|
152
|
+
*/
|
153
|
+
unsigned dwarf_set_harmless_error_list_size(Dwarf_Debug dbg,
|
154
|
+
unsigned maxcount )
|
155
|
+
{
|
156
|
+
struct Dwarf_Harmless_s *dhp = &dbg->de_harmless_errors;
|
157
|
+
unsigned prevcount = dhp->dh_maxcount;
|
158
|
+
if (maxcount != 0) {
|
159
|
+
++maxcount;
|
160
|
+
if (maxcount != dhp->dh_maxcount) {
|
161
|
+
/* Assign transfers 'ownership' of the malloc areas
|
162
|
+
to oldarray. */
|
163
|
+
struct Dwarf_Harmless_s oldarray = *dhp;
|
164
|
+
/* Do not double increment the max, the init() func
|
165
|
+
increments it too. */
|
166
|
+
dwarf_harmless_init(dhp,maxcount-1);
|
167
|
+
if (oldarray.dh_next_to_use != oldarray.dh_first) {
|
168
|
+
unsigned i = 0;
|
169
|
+
for (i = oldarray.dh_first; i != oldarray.dh_next_to_use;
|
170
|
+
i = (i+1)%oldarray.dh_maxcount) {
|
171
|
+
dwarf_insert_harmless_error(dbg,oldarray.dh_errors[i]);
|
172
|
+
}
|
173
|
+
if (oldarray.dh_errs_count > dhp->dh_errs_count) {
|
174
|
+
dhp->dh_errs_count = oldarray.dh_errs_count;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
dwarf_harmless_cleanout(&oldarray);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
return prevcount-1;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Only callable from within libdwarf (as a practical matter)
|
184
|
+
*/
|
185
|
+
void
|
186
|
+
dwarf_harmless_init(struct Dwarf_Harmless_s *dhp,unsigned size)
|
187
|
+
{
|
188
|
+
unsigned i = 0;
|
189
|
+
memset(dhp,0,sizeof(*dhp));
|
190
|
+
dhp->dh_maxcount = size +1;
|
191
|
+
dhp->dh_errors = (char **)malloc(sizeof( char *) *dhp->dh_maxcount);
|
192
|
+
if (!dhp->dh_errors) {
|
193
|
+
dhp->dh_maxcount = 0;
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
|
197
|
+
for (i = 0; i < dhp->dh_maxcount; ++i) {
|
198
|
+
char *newstr =
|
199
|
+
(char *)malloc(DW_HARMLESS_ERROR_MSG_STRING_SIZE);
|
200
|
+
dhp->dh_errors[i] = newstr;
|
201
|
+
if (!newstr) {
|
202
|
+
dhp->dh_maxcount = 0;
|
203
|
+
/* Let it leak, the leak is a constrained amount. */
|
204
|
+
dhp->dh_errors = 0;
|
205
|
+
return;
|
206
|
+
}
|
207
|
+
/* We make the string content well-defined by an initial
|
208
|
+
NUL byte, but this is not really necessary. */
|
209
|
+
newstr[0] = 0;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
void
|
214
|
+
dwarf_harmless_cleanout(struct Dwarf_Harmless_s *dhp)
|
215
|
+
{
|
216
|
+
unsigned i = 0;
|
217
|
+
if (!dhp->dh_errors) {
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
for (i = 0; i < dhp->dh_maxcount; ++i) {
|
221
|
+
free(dhp->dh_errors[i]);
|
222
|
+
dhp->dh_errors[i] = 0;
|
223
|
+
}
|
224
|
+
free(dhp->dh_errors);
|
225
|
+
dhp->dh_errors = 0;
|
226
|
+
dhp->dh_maxcount = 0;
|
227
|
+
}
|
228
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2010 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
|
+
|
28
|
+
|
29
|
+
void dwarf_harmless_init(struct Dwarf_Harmless_s *dhp,unsigned size);
|
30
|
+
void dwarf_harmless_cleanout(struct Dwarf_Harmless_s *dhp);
|
31
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2000, 2002, 2004 Silicon Graphics, Inc. All Rights Reserved.
|
4
|
+
Portions Copyright 2008-2010 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
|
+
#ifndef DWARF_INCL_H
|
31
|
+
#define DWARF_INCL_H
|
32
|
+
#if (!defined(HAVE_RAW_LIBELF_OK) && defined(HAVE_LIBELF_OFF64_OK) )
|
33
|
+
/* At a certain point libelf.h requires _GNU_SOURCE.
|
34
|
+
here we assume the criteria in configure determine that
|
35
|
+
usefully.
|
36
|
+
*/
|
37
|
+
#define _GNU_SOURCE 1
|
38
|
+
#endif
|
39
|
+
|
40
|
+
#ifdef HAVE_STDAFX_H /* Windows specific. */
|
41
|
+
#include "stdafx.h"
|
42
|
+
#endif /* HAVE_STDAFX_H */
|
43
|
+
|
44
|
+
#include "libdwarfdefs.h"
|
45
|
+
#include <string.h>
|
46
|
+
|
47
|
+
#ifdef HAVE_ELF_H
|
48
|
+
#include <elf.h>
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#include <limits.h>
|
52
|
+
#include <dwarf.h>
|
53
|
+
#include <libdwarf.h>
|
54
|
+
|
55
|
+
#include "dwarf_base_types.h"
|
56
|
+
#include "dwarf_alloc.h"
|
57
|
+
#include "dwarf_xu_index.h"
|
58
|
+
#include "dwarf_opaque.h"
|
59
|
+
#include "dwarf_error.h"
|
60
|
+
#include "dwarf_util.h"
|
61
|
+
#endif /* DWARF_INCL_H */
|
@@ -0,0 +1,1263 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (C) 2000,2002,2003,2004,2005 Silicon Graphics, Inc. All Rights Reserved.
|
4
|
+
Portions Copyright (C) 2008-2010 Arxan Technologies, Inc. All Rights Reserved.
|
5
|
+
Portions Copyright (C) 2009-2013 David Anderson. All Rights Reserved.
|
6
|
+
Portions Copyright (C) 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
|
+
|
33
|
+
#include <stdio.h>
|
34
|
+
#include <sys/stat.h>
|
35
|
+
#include <sys/types.h>
|
36
|
+
#include <string.h>
|
37
|
+
#include <stdlib.h>
|
38
|
+
|
39
|
+
#include "dwarf_incl.h"
|
40
|
+
#include "dwarf_harmless.h"
|
41
|
+
|
42
|
+
/* For consistency, use the HAVE_LIBELF_H symbol */
|
43
|
+
#ifdef HAVE_ELF_H
|
44
|
+
#include <elf.h>
|
45
|
+
#endif
|
46
|
+
#ifdef HAVE_LIBELF_H
|
47
|
+
#include <libelf.h>
|
48
|
+
#else
|
49
|
+
#ifdef HAVE_LIBELF_LIBELF_H
|
50
|
+
#include <libelf/libelf.h>
|
51
|
+
#endif
|
52
|
+
#endif
|
53
|
+
|
54
|
+
#define DWARF_DBG_ERROR(dbg,errval,retval) \
|
55
|
+
_dwarf_error(dbg, error, errval); return(retval);
|
56
|
+
|
57
|
+
#define FALSE 0
|
58
|
+
#define TRUE 1
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
/* This static is copied to the dbg on dbg init
|
63
|
+
so that the static need not be referenced at
|
64
|
+
run time, preserving better locality of
|
65
|
+
reference.
|
66
|
+
Value is 0 means do the string check.
|
67
|
+
Value non-zero means do not do the check.
|
68
|
+
*/
|
69
|
+
static Dwarf_Small _dwarf_assume_string_in_bounds;
|
70
|
+
static Dwarf_Small _dwarf_apply_relocs = 1;
|
71
|
+
|
72
|
+
/* Call this after calling dwarf_init but before doing anything else.
|
73
|
+
It applies to all objects, not just the current object. */
|
74
|
+
int
|
75
|
+
dwarf_set_reloc_application(int apply)
|
76
|
+
{
|
77
|
+
int oldval = _dwarf_apply_relocs;
|
78
|
+
_dwarf_apply_relocs = apply;
|
79
|
+
return oldval;
|
80
|
+
}
|
81
|
+
|
82
|
+
int
|
83
|
+
dwarf_set_stringcheck(int newval)
|
84
|
+
{
|
85
|
+
int oldval = _dwarf_assume_string_in_bounds;
|
86
|
+
|
87
|
+
_dwarf_assume_string_in_bounds = newval;
|
88
|
+
return oldval;
|
89
|
+
}
|
90
|
+
|
91
|
+
/* Unifies the basic duplicate/empty testing and section
|
92
|
+
data setting to one place. */
|
93
|
+
static int
|
94
|
+
get_basic_section_data(Dwarf_Debug dbg,
|
95
|
+
struct Dwarf_Section_s *secdata,
|
96
|
+
struct Dwarf_Obj_Access_Section_s *doas,
|
97
|
+
Dwarf_Half section_index,
|
98
|
+
Dwarf_Error* error,
|
99
|
+
int duperr, int emptyerr )
|
100
|
+
{
|
101
|
+
/* There is an elf convention that section index 0 is reserved,
|
102
|
+
and that section is always empty.
|
103
|
+
Non-elf object formats must honor that by ensuring that
|
104
|
+
(when they assign numbers to 'sections' or 'section-like-things')
|
105
|
+
they never assign a real section section-number 0 to dss_index. */
|
106
|
+
if (secdata->dss_index != 0) {
|
107
|
+
DWARF_DBG_ERROR(dbg, duperr, DW_DLV_ERROR);
|
108
|
+
}
|
109
|
+
if (doas->size == 0) {
|
110
|
+
if (emptyerr == 0 ) {
|
111
|
+
/* Allow empty section. */
|
112
|
+
return DW_DLV_OK;
|
113
|
+
}
|
114
|
+
/* Know no reason to allow section */
|
115
|
+
DWARF_DBG_ERROR(dbg, emptyerr, DW_DLV_ERROR);
|
116
|
+
}
|
117
|
+
secdata->dss_index = section_index;
|
118
|
+
secdata->dss_size = doas->size;
|
119
|
+
secdata->dss_addr = doas->addr;
|
120
|
+
secdata->dss_link = doas->link;
|
121
|
+
secdata->dss_entrysize = doas->entrysize;
|
122
|
+
return DW_DLV_OK;
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
static void
|
127
|
+
add_rela_data( struct Dwarf_Section_s *secdata,
|
128
|
+
struct Dwarf_Obj_Access_Section_s *doas,
|
129
|
+
Dwarf_Half section_index)
|
130
|
+
{
|
131
|
+
secdata->dss_reloc_index = section_index;
|
132
|
+
secdata->dss_reloc_size = doas->size;
|
133
|
+
secdata->dss_reloc_entrysize = doas->entrysize;
|
134
|
+
secdata->dss_reloc_addr = doas->addr;
|
135
|
+
secdata->dss_reloc_symtab = doas->link;
|
136
|
+
secdata->dss_reloc_link = doas->link;
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
/* Used to add the specific information for a debug related section
|
142
|
+
Called on each section of interest by section name.
|
143
|
+
DWARF_MAX_DEBUG_SECTIONS must be large enough to allow
|
144
|
+
that all sections of interest fit in the table.
|
145
|
+
*/
|
146
|
+
static int
|
147
|
+
add_debug_section_info(Dwarf_Debug dbg,
|
148
|
+
const char *name,
|
149
|
+
struct Dwarf_Section_s *secdata,
|
150
|
+
int duperr,int emptyerr,int have_dwarf,
|
151
|
+
int *err)
|
152
|
+
{
|
153
|
+
unsigned total_entries = dbg->de_debug_sections_total_entries;
|
154
|
+
if (secdata->dss_is_in_use) {
|
155
|
+
*err = duperr;
|
156
|
+
return DW_DLV_ERROR;
|
157
|
+
}
|
158
|
+
if (total_entries < DWARF_MAX_DEBUG_SECTIONS) {
|
159
|
+
struct Dwarf_dbg_sect_s *debug_section =
|
160
|
+
&dbg->de_debug_sections[total_entries];
|
161
|
+
secdata->dss_is_in_use = TRUE;
|
162
|
+
debug_section->ds_name = name;
|
163
|
+
debug_section->ds_secdata = secdata;
|
164
|
+
secdata->dss_name = name;
|
165
|
+
debug_section->ds_duperr = duperr;
|
166
|
+
debug_section->ds_emptyerr = emptyerr;
|
167
|
+
debug_section->ds_have_dwarf = have_dwarf;
|
168
|
+
++dbg->de_debug_sections_total_entries;
|
169
|
+
return DW_DLV_OK;
|
170
|
+
}
|
171
|
+
/* This represents a bug in libdwarf.
|
172
|
+
Mis-setup-DWARF_MAX_DEBUG_SECTIONS.
|
173
|
+
Or possibly a use of section groups that is
|
174
|
+
not supported. */
|
175
|
+
*err = DW_DLE_TOO_MANY_DEBUG;
|
176
|
+
return DW_DLV_ERROR;
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
/* If running this long set of tests is slow
|
181
|
+
enough to matter one could set up a local
|
182
|
+
tsearch tree with all this content and search
|
183
|
+
it instead of this set of sequential tests.
|
184
|
+
Or use a switch(){} here with a search tree
|
185
|
+
to to turn name into index for the switch(). */
|
186
|
+
static int
|
187
|
+
enter_section_in_de_debug_sections_array(Dwarf_Debug dbg,
|
188
|
+
const char *scn_name,
|
189
|
+
int *err)
|
190
|
+
{
|
191
|
+
int sectionerr = 0;
|
192
|
+
/* Setup the table that contains the basic information about the
|
193
|
+
sections that are DWARF related. The entries are very unlikely
|
194
|
+
to change very often. */
|
195
|
+
if(!strcmp(scn_name,".debug_info")) {
|
196
|
+
sectionerr = add_debug_section_info(dbg,".debug_info",
|
197
|
+
&dbg->de_debug_info,
|
198
|
+
DW_DLE_DEBUG_INFO_DUPLICATE,DW_DLE_DEBUG_INFO_NULL,
|
199
|
+
TRUE,err);
|
200
|
+
if (sectionerr != DW_DLV_OK) {
|
201
|
+
return sectionerr;
|
202
|
+
}
|
203
|
+
return DW_DLV_OK;
|
204
|
+
}
|
205
|
+
if(!strcmp(scn_name,".debug_info.dwo")) {
|
206
|
+
sectionerr = add_debug_section_info(dbg,".debug_info.dwo",
|
207
|
+
&dbg->de_debug_info,
|
208
|
+
DW_DLE_DEBUG_INFO_DUPLICATE,DW_DLE_DEBUG_INFO_NULL,
|
209
|
+
TRUE,err);
|
210
|
+
if (sectionerr != DW_DLV_OK) {
|
211
|
+
return sectionerr;
|
212
|
+
}
|
213
|
+
return DW_DLV_OK;
|
214
|
+
}
|
215
|
+
if(!strcmp(scn_name,".debug_types")) {
|
216
|
+
sectionerr = add_debug_section_info(dbg,".debug_types",
|
217
|
+
&dbg->de_debug_types,
|
218
|
+
DW_DLE_DEBUG_TYPES_DUPLICATE,DW_DLE_DEBUG_TYPES_NULL,
|
219
|
+
TRUE,err);
|
220
|
+
if (sectionerr != DW_DLV_OK) {
|
221
|
+
return sectionerr;
|
222
|
+
}
|
223
|
+
return DW_DLV_OK;
|
224
|
+
}
|
225
|
+
if(!strcmp(scn_name,".debug_types.dwo")) {
|
226
|
+
sectionerr = add_debug_section_info(dbg,".debug_types.dwo",
|
227
|
+
&dbg->de_debug_types,
|
228
|
+
DW_DLE_DEBUG_TYPES_DUPLICATE,DW_DLE_DEBUG_TYPES_NULL,
|
229
|
+
TRUE,err);
|
230
|
+
if (sectionerr != DW_DLV_OK) {
|
231
|
+
return sectionerr;
|
232
|
+
}
|
233
|
+
return DW_DLV_OK;
|
234
|
+
|
235
|
+
}
|
236
|
+
if(!strcmp(scn_name,".debug_abbrev")) {
|
237
|
+
sectionerr = add_debug_section_info(dbg,".debug_abbrev",
|
238
|
+
&dbg->de_debug_abbrev, /*03*/
|
239
|
+
DW_DLE_DEBUG_ABBREV_DUPLICATE,DW_DLE_DEBUG_ABBREV_NULL,
|
240
|
+
FALSE,err);
|
241
|
+
if (sectionerr != DW_DLV_OK) {
|
242
|
+
return sectionerr;
|
243
|
+
}
|
244
|
+
return DW_DLV_OK;
|
245
|
+
}
|
246
|
+
if(!strcmp(scn_name,".debug_abbrev.dwo")) {
|
247
|
+
sectionerr = add_debug_section_info(dbg,".debug_abbrev.dwo",
|
248
|
+
&dbg->de_debug_abbrev, /*03*/
|
249
|
+
DW_DLE_DEBUG_ABBREV_DUPLICATE,DW_DLE_DEBUG_ABBREV_NULL,
|
250
|
+
FALSE,err);
|
251
|
+
if (sectionerr != DW_DLV_OK) {
|
252
|
+
return sectionerr;
|
253
|
+
}
|
254
|
+
return DW_DLV_OK;
|
255
|
+
}
|
256
|
+
if(!strcmp(scn_name,".debug_aranges")) {
|
257
|
+
sectionerr = add_debug_section_info(dbg,".debug_aranges",
|
258
|
+
&dbg->de_debug_aranges,
|
259
|
+
DW_DLE_DEBUG_ARANGES_DUPLICATE,0,
|
260
|
+
FALSE,err);
|
261
|
+
if (sectionerr != DW_DLV_OK) {
|
262
|
+
return sectionerr;
|
263
|
+
}
|
264
|
+
return DW_DLV_OK;
|
265
|
+
}
|
266
|
+
|
267
|
+
if(!strcmp(scn_name,".debug_line")) {
|
268
|
+
sectionerr = add_debug_section_info(dbg,".debug_line",
|
269
|
+
&dbg->de_debug_line,
|
270
|
+
DW_DLE_DEBUG_LINE_DUPLICATE,0,
|
271
|
+
FALSE,err);
|
272
|
+
if (sectionerr != DW_DLV_OK) {
|
273
|
+
return sectionerr;
|
274
|
+
}
|
275
|
+
return DW_DLV_OK;
|
276
|
+
}
|
277
|
+
if(!strcmp(scn_name,".debug_line_str")) {
|
278
|
+
sectionerr = add_debug_section_info(dbg,".debug_line_str",
|
279
|
+
&dbg->de_debug_line_str,
|
280
|
+
DW_DLE_DEBUG_LINE_DUPLICATE,0,
|
281
|
+
FALSE,err);
|
282
|
+
if (sectionerr != DW_DLV_OK) {
|
283
|
+
return sectionerr;
|
284
|
+
}
|
285
|
+
return DW_DLV_OK;
|
286
|
+
}
|
287
|
+
if(!strcmp(scn_name,".debug_line.dwo")) {
|
288
|
+
sectionerr = add_debug_section_info(dbg,".debug_line.dwo",
|
289
|
+
&dbg->de_debug_line,
|
290
|
+
DW_DLE_DEBUG_LINE_DUPLICATE,0,
|
291
|
+
FALSE,err);
|
292
|
+
if (sectionerr != DW_DLV_OK) {
|
293
|
+
return sectionerr;
|
294
|
+
}
|
295
|
+
return DW_DLV_OK;
|
296
|
+
}
|
297
|
+
if(!strcmp(scn_name,".debug_line_str")) {
|
298
|
+
sectionerr = add_debug_section_info(dbg,".debug_line_str",
|
299
|
+
&dbg->de_debug_line_str,
|
300
|
+
DW_DLE_DEBUG_LINE_STR_DUPLICATE,0,
|
301
|
+
FALSE,err);
|
302
|
+
if (sectionerr != DW_DLV_OK) {
|
303
|
+
return sectionerr;
|
304
|
+
}
|
305
|
+
return DW_DLV_OK;
|
306
|
+
}
|
307
|
+
|
308
|
+
|
309
|
+
if(!strcmp(scn_name,".debug_frame")) {
|
310
|
+
sectionerr = add_debug_section_info(dbg,".debug_frame",
|
311
|
+
&dbg->de_debug_frame,
|
312
|
+
DW_DLE_DEBUG_FRAME_DUPLICATE,0,
|
313
|
+
TRUE,err);
|
314
|
+
if (sectionerr != DW_DLV_OK) {
|
315
|
+
return sectionerr;
|
316
|
+
}
|
317
|
+
return DW_DLV_OK;
|
318
|
+
}
|
319
|
+
if(!strcmp(scn_name,".eh_frame")) {
|
320
|
+
/* gnu egcs-1.1.2 data */
|
321
|
+
sectionerr = add_debug_section_info(dbg,".eh_frame",
|
322
|
+
&dbg->de_debug_frame_eh_gnu,
|
323
|
+
DW_DLE_DEBUG_FRAME_DUPLICATE,0,
|
324
|
+
TRUE,err);
|
325
|
+
if (sectionerr != DW_DLV_OK) {
|
326
|
+
return sectionerr;
|
327
|
+
}
|
328
|
+
return DW_DLV_OK;
|
329
|
+
}
|
330
|
+
if(!strcmp(scn_name,".debug_loc")) {
|
331
|
+
sectionerr = add_debug_section_info(dbg,".debug_loc",
|
332
|
+
&dbg->de_debug_loc,
|
333
|
+
DW_DLE_DEBUG_LOC_DUPLICATE,0,
|
334
|
+
FALSE,err);
|
335
|
+
if (sectionerr != DW_DLV_OK) {
|
336
|
+
return sectionerr;
|
337
|
+
}
|
338
|
+
return DW_DLV_OK;
|
339
|
+
}
|
340
|
+
if(!strcmp(scn_name,".debug_loc.dwo")) {
|
341
|
+
sectionerr = add_debug_section_info(dbg,".debug_loc.dwo",
|
342
|
+
&dbg->de_debug_loc,
|
343
|
+
DW_DLE_DEBUG_LOC_DUPLICATE,0,
|
344
|
+
FALSE,err);
|
345
|
+
if (sectionerr != DW_DLV_OK) {
|
346
|
+
return sectionerr;
|
347
|
+
}
|
348
|
+
return DW_DLV_OK;
|
349
|
+
}
|
350
|
+
if(!strcmp(scn_name,".debug_pubnames")) {
|
351
|
+
sectionerr = add_debug_section_info(dbg,".debug_pubnames",
|
352
|
+
&dbg->de_debug_pubnames,
|
353
|
+
DW_DLE_DEBUG_PUBNAMES_DUPLICATE,0,
|
354
|
+
FALSE,err);
|
355
|
+
if (sectionerr != DW_DLV_OK) {
|
356
|
+
return sectionerr;
|
357
|
+
}
|
358
|
+
return DW_DLV_OK;
|
359
|
+
}
|
360
|
+
if(!strcmp(scn_name,".debug_str")) {
|
361
|
+
sectionerr = add_debug_section_info(dbg,".debug_str",
|
362
|
+
&dbg->de_debug_str,
|
363
|
+
DW_DLE_DEBUG_STR_DUPLICATE,0,
|
364
|
+
FALSE,err);
|
365
|
+
if (sectionerr != DW_DLV_OK) {
|
366
|
+
return sectionerr;
|
367
|
+
}
|
368
|
+
return DW_DLV_OK;
|
369
|
+
}
|
370
|
+
if(!strcmp(scn_name,".debug_str.dwo")) {
|
371
|
+
sectionerr = add_debug_section_info(dbg,".debug_str.dwo",
|
372
|
+
&dbg->de_debug_str,
|
373
|
+
DW_DLE_DEBUG_STR_DUPLICATE,0,
|
374
|
+
FALSE,err);
|
375
|
+
if (sectionerr != DW_DLV_OK) {
|
376
|
+
return sectionerr;
|
377
|
+
}
|
378
|
+
return DW_DLV_OK;
|
379
|
+
}
|
380
|
+
if(!strcmp(scn_name,".debug_funcnames")) {
|
381
|
+
/* SGI IRIX-only. */
|
382
|
+
sectionerr = add_debug_section_info(dbg,".debug_funcnames",
|
383
|
+
&dbg->de_debug_funcnames,
|
384
|
+
/*11*/
|
385
|
+
DW_DLE_DEBUG_FUNCNAMES_DUPLICATE,0,
|
386
|
+
FALSE,err);
|
387
|
+
if (sectionerr != DW_DLV_OK) {
|
388
|
+
return sectionerr;
|
389
|
+
}
|
390
|
+
return DW_DLV_OK;
|
391
|
+
}
|
392
|
+
if(!strcmp(scn_name,".debug_typenames")) {
|
393
|
+
/* SGI IRIX-only, created years before DWARF3. Content
|
394
|
+
essentially identical to .debug_pubtypes. */
|
395
|
+
sectionerr = add_debug_section_info(dbg,".debug_typenames",
|
396
|
+
&dbg->de_debug_typenames,
|
397
|
+
/*12*/
|
398
|
+
DW_DLE_DEBUG_TYPENAMES_DUPLICATE,0,
|
399
|
+
FALSE,err);
|
400
|
+
if (sectionerr != DW_DLV_OK) {
|
401
|
+
return sectionerr;
|
402
|
+
}
|
403
|
+
return DW_DLV_OK;
|
404
|
+
}
|
405
|
+
if(!strcmp(scn_name,".debug_pubtypes")) {
|
406
|
+
/* Section new in DWARF3. */
|
407
|
+
sectionerr = add_debug_section_info(dbg,".debug_pubtypes",
|
408
|
+
&dbg->de_debug_pubtypes,
|
409
|
+
/*13*/
|
410
|
+
DW_DLE_DEBUG_PUBTYPES_DUPLICATE,0,
|
411
|
+
FALSE,err);
|
412
|
+
if (sectionerr != DW_DLV_OK) {
|
413
|
+
return sectionerr;
|
414
|
+
}
|
415
|
+
return DW_DLV_OK;
|
416
|
+
}
|
417
|
+
if(!strcmp(scn_name,".debug_varnames")) {
|
418
|
+
/* SGI IRIX-only. */
|
419
|
+
sectionerr = add_debug_section_info(dbg,".debug_varnames",
|
420
|
+
&dbg->de_debug_varnames,
|
421
|
+
DW_DLE_DEBUG_VARNAMES_DUPLICATE,0,
|
422
|
+
FALSE,err);
|
423
|
+
if (sectionerr != DW_DLV_OK) {
|
424
|
+
return sectionerr;
|
425
|
+
}
|
426
|
+
return DW_DLV_OK;
|
427
|
+
}
|
428
|
+
if(!strcmp(scn_name,".debug_weaknames")) {
|
429
|
+
/* SGI IRIX-only. */
|
430
|
+
sectionerr = add_debug_section_info(dbg,".debug_weaknames",
|
431
|
+
&dbg->de_debug_weaknames,
|
432
|
+
DW_DLE_DEBUG_WEAKNAMES_DUPLICATE,0,
|
433
|
+
FALSE,err);
|
434
|
+
if (sectionerr != DW_DLV_OK) {
|
435
|
+
return sectionerr;
|
436
|
+
}
|
437
|
+
return DW_DLV_OK;
|
438
|
+
}
|
439
|
+
if(!strcmp(scn_name,".debug_macinfo")) {
|
440
|
+
sectionerr = add_debug_section_info(dbg,".debug_macinfo",
|
441
|
+
&dbg->de_debug_macinfo,
|
442
|
+
DW_DLE_DEBUG_MACINFO_DUPLICATE,0,
|
443
|
+
FALSE,err);
|
444
|
+
if (sectionerr != DW_DLV_OK) {
|
445
|
+
return sectionerr;
|
446
|
+
}
|
447
|
+
return DW_DLV_OK;
|
448
|
+
}
|
449
|
+
/* ".debug_macinfo.dwo" is not allowed. */
|
450
|
+
|
451
|
+
|
452
|
+
if(!strcmp(scn_name,".debug_macro")) { /* DWARF5 */
|
453
|
+
sectionerr = add_debug_section_info(dbg,".debug_macro",
|
454
|
+
&dbg->de_debug_macro,
|
455
|
+
DW_DLE_DEBUG_MACRO_DUPLICATE,0,
|
456
|
+
FALSE,err);
|
457
|
+
if (sectionerr != DW_DLV_OK) {
|
458
|
+
return sectionerr;
|
459
|
+
}
|
460
|
+
return DW_DLV_OK;
|
461
|
+
}
|
462
|
+
if(!strcmp(scn_name,".debug_macro.dwo")) { /* DWARF5 */
|
463
|
+
sectionerr = add_debug_section_info(dbg,".debug_macro.dwo",
|
464
|
+
&dbg->de_debug_macro,
|
465
|
+
DW_DLE_DEBUG_MACRO_DUPLICATE,0,
|
466
|
+
FALSE,err);
|
467
|
+
if (sectionerr != DW_DLV_OK) {
|
468
|
+
return sectionerr;
|
469
|
+
}
|
470
|
+
return DW_DLV_OK;
|
471
|
+
}
|
472
|
+
if(!strcmp(scn_name,".debug_ranges")) {
|
473
|
+
sectionerr = add_debug_section_info(dbg,".debug_ranges",
|
474
|
+
&dbg->de_debug_ranges,
|
475
|
+
DW_DLE_DEBUG_RANGES_DUPLICATE,0,
|
476
|
+
TRUE,err);
|
477
|
+
if (sectionerr != DW_DLV_OK) {
|
478
|
+
return sectionerr;
|
479
|
+
}
|
480
|
+
return DW_DLV_OK;
|
481
|
+
}
|
482
|
+
/* No .debug_ranges.dwo allowed. */
|
483
|
+
|
484
|
+
if(!strcmp(scn_name,".debug_str_offsets")) {
|
485
|
+
/* New DWARF5 */
|
486
|
+
sectionerr = add_debug_section_info(dbg,".debug_str_offsets",
|
487
|
+
&dbg->de_debug_str_offsets,
|
488
|
+
DW_DLE_DEBUG_STR_OFFSETS_DUPLICATE,0,
|
489
|
+
TRUE,err);
|
490
|
+
if (sectionerr != DW_DLV_OK) {
|
491
|
+
return sectionerr;
|
492
|
+
}
|
493
|
+
return DW_DLV_OK;
|
494
|
+
}
|
495
|
+
if(!strcmp(scn_name,".debug_str_offsets.dwo")) {
|
496
|
+
/* New DWARF5 */
|
497
|
+
sectionerr = add_debug_section_info(dbg,".debug_str_offsets.dwo",
|
498
|
+
&dbg->de_debug_str_offsets,
|
499
|
+
DW_DLE_DEBUG_STR_OFFSETS_DUPLICATE,0,
|
500
|
+
TRUE,err);
|
501
|
+
if (sectionerr != DW_DLV_OK) {
|
502
|
+
return sectionerr;
|
503
|
+
}
|
504
|
+
return DW_DLV_OK;
|
505
|
+
}
|
506
|
+
if(!strcmp(scn_name,".debug_sup")) { /* DWARF5 */
|
507
|
+
/* New DWARF5 */
|
508
|
+
sectionerr = add_debug_section_info(dbg,".debug_sup",
|
509
|
+
&dbg->de_debug_sup,
|
510
|
+
DW_DLE_DEBUG_SUP_DUPLICATE,0,
|
511
|
+
TRUE,err);
|
512
|
+
if (sectionerr != DW_DLV_OK) {
|
513
|
+
return sectionerr;
|
514
|
+
}
|
515
|
+
return DW_DLV_OK;
|
516
|
+
}
|
517
|
+
/* No .debug_sup.dwo allowed. */
|
518
|
+
|
519
|
+
if(!strcmp(scn_name,".symtab")) {
|
520
|
+
sectionerr = add_debug_section_info(dbg,".symtab",
|
521
|
+
&dbg->de_elf_symtab,
|
522
|
+
DW_DLE_DEBUG_SYMTAB_ERR,0,
|
523
|
+
FALSE,err);
|
524
|
+
if (sectionerr != DW_DLV_OK) {
|
525
|
+
return sectionerr;
|
526
|
+
}
|
527
|
+
return DW_DLV_OK;
|
528
|
+
}
|
529
|
+
if(!strcmp(scn_name,".strtab")) {
|
530
|
+
sectionerr = add_debug_section_info(dbg,".strtab",
|
531
|
+
&dbg->de_elf_strtab,
|
532
|
+
DW_DLE_DEBUG_STRTAB_ERR,0,
|
533
|
+
FALSE,err);
|
534
|
+
if (sectionerr != DW_DLV_OK) {
|
535
|
+
return sectionerr;
|
536
|
+
}
|
537
|
+
return DW_DLV_OK;
|
538
|
+
}
|
539
|
+
if(!strcmp(scn_name,".debug_addr")) {
|
540
|
+
/* New DWARF5 */
|
541
|
+
sectionerr = add_debug_section_info(dbg,".debug_addr",
|
542
|
+
&dbg->de_debug_addr,
|
543
|
+
DW_DLE_DEBUG_ADDR_DUPLICATE,0,
|
544
|
+
TRUE,err);
|
545
|
+
if (sectionerr != DW_DLV_OK) {
|
546
|
+
return sectionerr;
|
547
|
+
}
|
548
|
+
return DW_DLV_OK;
|
549
|
+
}
|
550
|
+
/* No .debug_addr.dwo allowed. */
|
551
|
+
|
552
|
+
if(!strcmp(scn_name,".gdb_index")) {
|
553
|
+
/* gdb added this. */
|
554
|
+
sectionerr = add_debug_section_info(dbg,".gdb_index",
|
555
|
+
&dbg->de_debug_gdbindex,
|
556
|
+
DW_DLE_DUPLICATE_GDB_INDEX,0,
|
557
|
+
FALSE,err);
|
558
|
+
if (sectionerr != DW_DLV_OK) {
|
559
|
+
return sectionerr;
|
560
|
+
}
|
561
|
+
return DW_DLV_OK;
|
562
|
+
}
|
563
|
+
if(!strcmp(scn_name,".debug_names")) { /* NEW DWARF5 */
|
564
|
+
sectionerr = add_debug_section_info(dbg,".debug_names",
|
565
|
+
&dbg->de_debug_names,
|
566
|
+
DW_DLE_DEBUG_NAMES_DUPLICATE,0,
|
567
|
+
FALSE,err);
|
568
|
+
if (sectionerr != DW_DLV_OK) {
|
569
|
+
return sectionerr;
|
570
|
+
}
|
571
|
+
return DW_DLV_OK;
|
572
|
+
}
|
573
|
+
/* No .debug_names.dwo is allowed. */
|
574
|
+
if(!strcmp(scn_name,".debug_cu_index")) {
|
575
|
+
/* gdb added this in DW4. It is in standard DWARF5 */
|
576
|
+
sectionerr = add_debug_section_info(dbg,".debug_cu_index",
|
577
|
+
&dbg->de_debug_cu_index,
|
578
|
+
DW_DLE_DUPLICATE_CU_INDEX,0,
|
579
|
+
FALSE,err);
|
580
|
+
if (sectionerr != DW_DLV_OK) {
|
581
|
+
return sectionerr;
|
582
|
+
}
|
583
|
+
return DW_DLV_OK;
|
584
|
+
}
|
585
|
+
if(!strcmp(scn_name,".debug_tu_index")) {
|
586
|
+
/* gdb added this in DW4. It is in standard DWARF5 */
|
587
|
+
sectionerr = add_debug_section_info(dbg,".debug_tu_index",
|
588
|
+
&dbg->de_debug_tu_index,
|
589
|
+
DW_DLE_DUPLICATE_TU_INDEX,0,
|
590
|
+
FALSE,err);
|
591
|
+
if (sectionerr != DW_DLV_OK) {
|
592
|
+
return sectionerr;
|
593
|
+
}
|
594
|
+
return DW_DLV_OK;
|
595
|
+
}
|
596
|
+
return DW_DLV_NO_ENTRY;
|
597
|
+
}
|
598
|
+
|
599
|
+
static int
|
600
|
+
is_section_known_already(Dwarf_Debug dbg,
|
601
|
+
const char *scn_name,
|
602
|
+
unsigned *found_section_number,
|
603
|
+
unsigned start_number,
|
604
|
+
int *err)
|
605
|
+
{
|
606
|
+
unsigned i = start_number;
|
607
|
+
for ( ; i < dbg->de_debug_sections_total_entries; ++i) {
|
608
|
+
struct Dwarf_dbg_sect_s *section = &dbg->de_debug_sections[i];
|
609
|
+
if (!strcmp(scn_name, section->ds_name)) {
|
610
|
+
*found_section_number = i;
|
611
|
+
return DW_DLV_OK;
|
612
|
+
}
|
613
|
+
}
|
614
|
+
return DW_DLV_NO_ENTRY;
|
615
|
+
}
|
616
|
+
|
617
|
+
/* Given an Elf ptr, set up dbg with pointers
|
618
|
+
to all the Dwarf data sections.
|
619
|
+
Return NULL on error.
|
620
|
+
|
621
|
+
This function is also responsible for determining
|
622
|
+
whether the given object contains Dwarf information
|
623
|
+
or not. The test currently used is that it contains
|
624
|
+
either a .debug_info or a .debug_frame section. If
|
625
|
+
not, it returns DW_DLV_NO_ENTRY causing dwarf_init() also to
|
626
|
+
return DW_DLV_NO_ENTRY. Earlier, we had thought of using only
|
627
|
+
the presence/absence of .debug_info to test, but we
|
628
|
+
added .debug_frame since there could be stripped objects
|
629
|
+
that have only a .debug_frame section for exception
|
630
|
+
processing.
|
631
|
+
DW_DLV_NO_ENTRY or DW_DLV_OK or DW_DLV_ERROR
|
632
|
+
|
633
|
+
This does not allow for section-groups in object files,
|
634
|
+
for which many .debug_info (and other DWARF) sections may exist.
|
635
|
+
|
636
|
+
We process. .rela (SHT_RELA) but not .rel (SHT_REL)
|
637
|
+
sections because with .rela the referencing section
|
638
|
+
offset value is zero whereas with .rel the
|
639
|
+
referencing section value is already correct for
|
640
|
+
the object itself. In other words, we do it because
|
641
|
+
of the definition of .rela relocations in Elf.
|
642
|
+
*/
|
643
|
+
|
644
|
+
static int
|
645
|
+
this_section_dwarf_relevant(const char *scn_name,int type)
|
646
|
+
{
|
647
|
+
/* A small helper function for _dwarf_setup(). */
|
648
|
+
if (strncmp(scn_name, ".debug_", 7)
|
649
|
+
&& strcmp(scn_name, ".eh_frame")
|
650
|
+
&& strcmp(scn_name, ".symtab")
|
651
|
+
&& strcmp(scn_name, ".strtab")
|
652
|
+
&& strcmp(scn_name, ".gdb_index")
|
653
|
+
&& strncmp(scn_name, ".rela.",6)
|
654
|
+
/* For an object file with incorrect rela section name,
|
655
|
+
readelf prints correct debug information,
|
656
|
+
as the tool takes the section type instead
|
657
|
+
of the section name. Include the incorrect
|
658
|
+
section name, until this test uses the section type. */
|
659
|
+
&& type != SHT_RELA) {
|
660
|
+
/* Other sections should be ignored, they
|
661
|
+
are not relevant for DWARF data. */
|
662
|
+
return FALSE;
|
663
|
+
}
|
664
|
+
/* This is one of ours. */
|
665
|
+
return TRUE;
|
666
|
+
}
|
667
|
+
|
668
|
+
|
669
|
+
static int
|
670
|
+
_dwarf_setup(Dwarf_Debug dbg, Dwarf_Error * error)
|
671
|
+
{
|
672
|
+
const char *scn_name = 0;
|
673
|
+
int foundDwarf = 0;
|
674
|
+
struct Dwarf_Obj_Access_Interface_s * obj = 0;
|
675
|
+
|
676
|
+
Dwarf_Endianness endianness;
|
677
|
+
|
678
|
+
/* Table with pointers to debug sections */
|
679
|
+
struct Dwarf_Section_s **sections = 0;
|
680
|
+
|
681
|
+
Dwarf_Unsigned section_count = 0;
|
682
|
+
Dwarf_Half obj_section_index = 0;
|
683
|
+
|
684
|
+
foundDwarf = FALSE;
|
685
|
+
|
686
|
+
dbg->de_assume_string_in_bounds = _dwarf_assume_string_in_bounds;
|
687
|
+
|
688
|
+
dbg->de_same_endian = 1;
|
689
|
+
dbg->de_copy_word = memcpy;
|
690
|
+
obj = dbg->de_obj_file;
|
691
|
+
endianness = obj->methods->get_byte_order(obj->object);
|
692
|
+
#ifdef WORDS_BIGENDIAN
|
693
|
+
dbg->de_big_endian_object = 1;
|
694
|
+
if (endianness == DW_OBJECT_LSB ) {
|
695
|
+
dbg->de_same_endian = 0;
|
696
|
+
dbg->de_big_endian_object = 0;
|
697
|
+
dbg->de_copy_word = _dwarf_memcpy_swap_bytes;
|
698
|
+
}
|
699
|
+
#else /* little endian */
|
700
|
+
dbg->de_big_endian_object = 0;
|
701
|
+
if (endianness == DW_OBJECT_MSB ) {
|
702
|
+
dbg->de_same_endian = 0;
|
703
|
+
dbg->de_big_endian_object = 1;
|
704
|
+
dbg->de_copy_word = _dwarf_memcpy_swap_bytes;
|
705
|
+
}
|
706
|
+
#endif /* !WORDS_BIGENDIAN */
|
707
|
+
|
708
|
+
|
709
|
+
/* The following de_length_size is Not Too Significant. Only used
|
710
|
+
one calculation, and an approximate one at that. */
|
711
|
+
dbg->de_length_size = obj->methods->get_length_size(obj->object);
|
712
|
+
dbg->de_pointer_size = obj->methods->get_pointer_size(obj->object);
|
713
|
+
|
714
|
+
section_count = obj->methods->get_section_count(obj->object);
|
715
|
+
|
716
|
+
/* Allocate space to record references to debug sections, that can
|
717
|
+
be referenced by RELA sections in the 'sh_info' field. */
|
718
|
+
sections = (struct Dwarf_Section_s **)calloc(section_count + 1,
|
719
|
+
sizeof(struct Dwarf_Section_s *));
|
720
|
+
if (!sections) {
|
721
|
+
/* Impossible case, we hope. Give up. */
|
722
|
+
_dwarf_error(dbg, error, DW_DLE_SECTION_ERROR);
|
723
|
+
return DW_DLV_ERROR;
|
724
|
+
}
|
725
|
+
|
726
|
+
/* We can skip index 0 when considering ELF files, but not other
|
727
|
+
object types. Indeed regardless of the object type we should
|
728
|
+
skip section 0 here.
|
729
|
+
This is a convention. We depend on it.
|
730
|
+
Non-elf object access code should
|
731
|
+
(in itself) understand we will index beginning at 1 and adjust
|
732
|
+
itself to deal with this Elf convention. Without this
|
733
|
+
convention various parts of the code in this file won't work correctly.
|
734
|
+
A dss_index of 0 must not be used, even though we start at 0
|
735
|
+
here. So the get_section_info() must adapt to the situation
|
736
|
+
(the elf version does automatically as a result of Elf having
|
737
|
+
a section zero with zero length and an empty name). */
|
738
|
+
for (obj_section_index = 0; obj_section_index < section_count;
|
739
|
+
++obj_section_index) {
|
740
|
+
|
741
|
+
struct Dwarf_Obj_Access_Section_s doas;
|
742
|
+
int res = DW_DLV_ERROR;
|
743
|
+
int err = 0;
|
744
|
+
|
745
|
+
memset(&doas,0,sizeof(doas));
|
746
|
+
res = obj->methods->get_section_info(obj->object,
|
747
|
+
obj_section_index,
|
748
|
+
&doas, &err);
|
749
|
+
if (res == DW_DLV_NO_ENTRY){
|
750
|
+
free(sections);
|
751
|
+
return res;
|
752
|
+
} else if (res == DW_DLV_ERROR){
|
753
|
+
free(sections);
|
754
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
755
|
+
}
|
756
|
+
|
757
|
+
scn_name = doas.name;
|
758
|
+
|
759
|
+
if (!this_section_dwarf_relevant(scn_name,doas.type) ) {
|
760
|
+
continue;
|
761
|
+
} else {
|
762
|
+
/* Build up the sections table and the
|
763
|
+
de_debug* etc pointers in Dwarf_Debug. */
|
764
|
+
struct Dwarf_dbg_sect_s *section;
|
765
|
+
|
766
|
+
int found_match = FALSE;
|
767
|
+
unsigned initial_start_number = 0;
|
768
|
+
unsigned dbg_section_number = 0;
|
769
|
+
res = is_section_known_already(dbg,scn_name,
|
770
|
+
&dbg_section_number,
|
771
|
+
initial_start_number,
|
772
|
+
&err);
|
773
|
+
if (res == DW_DLV_OK) {
|
774
|
+
/* DUPLICATE */
|
775
|
+
free(sections);
|
776
|
+
DWARF_DBG_ERROR(dbg, DW_DLE_SECTION_DUPLICATION,
|
777
|
+
DW_DLV_ERROR);
|
778
|
+
} else if (res == DW_DLV_ERROR) {
|
779
|
+
free(sections);
|
780
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
781
|
+
}
|
782
|
+
/* No entry: new-to-us section, the normal case. */
|
783
|
+
res = enter_section_in_de_debug_sections_array(dbg,scn_name,&err);
|
784
|
+
if (res == DW_DLV_OK) {
|
785
|
+
/* We just added a new entry in the dbg
|
786
|
+
de_debug_sections array. So we know its number. */
|
787
|
+
unsigned real_start_number =
|
788
|
+
dbg->de_debug_sections_total_entries-1;
|
789
|
+
res = is_section_known_already(dbg,scn_name,
|
790
|
+
&dbg_section_number,
|
791
|
+
real_start_number,
|
792
|
+
&err);
|
793
|
+
if (res == DW_DLV_OK) {
|
794
|
+
section = &dbg->de_debug_sections[dbg_section_number];
|
795
|
+
res = get_basic_section_data(dbg,
|
796
|
+
section->ds_secdata, &doas,
|
797
|
+
obj_section_index, error,
|
798
|
+
section->ds_duperr,
|
799
|
+
section->ds_emptyerr);
|
800
|
+
if (res != DW_DLV_OK) {
|
801
|
+
free(sections);
|
802
|
+
return res;
|
803
|
+
}
|
804
|
+
sections[obj_section_index] = section->ds_secdata;
|
805
|
+
foundDwarf += section->ds_have_dwarf;
|
806
|
+
found_match = TRUE;
|
807
|
+
/* Normal section set up.
|
808
|
+
Fall through. */
|
809
|
+
}else if (res == DW_DLV_NO_ENTRY) {
|
810
|
+
/* Some sort of bug in the code here.
|
811
|
+
Should be impossible to get here. */
|
812
|
+
free(sections);
|
813
|
+
DWARF_DBG_ERROR(dbg, DW_DLE_SECTION_ERROR, DW_DLV_ERROR);
|
814
|
+
} else {
|
815
|
+
free(sections);
|
816
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
817
|
+
}
|
818
|
+
} else if (res == DW_DLV_NO_ENTRY) {
|
819
|
+
/* We get here for relocation sections.
|
820
|
+
Fall through. */
|
821
|
+
} else {
|
822
|
+
free(sections);
|
823
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
824
|
+
}
|
825
|
+
|
826
|
+
if (!found_match) {
|
827
|
+
/* For an object file with incorrect rela section name,
|
828
|
+
the 'readelf' tool, prints correct debug information,
|
829
|
+
as the tool takes the section type instead
|
830
|
+
of the section name. If the current section
|
831
|
+
is a RELA one and the 'sh_info'
|
832
|
+
refers to a debug section, add the relocation data. */
|
833
|
+
if (doas.type == SHT_RELA) {
|
834
|
+
if ( doas.info < section_count) {
|
835
|
+
if (sections[doas.info]) {
|
836
|
+
add_rela_data(sections[doas.info],&doas,
|
837
|
+
obj_section_index);
|
838
|
+
}
|
839
|
+
} else {
|
840
|
+
/* Something is wrong with the ELF file. */
|
841
|
+
free(sections);
|
842
|
+
DWARF_DBG_ERROR(dbg, DW_DLE_ELF_SECT_ERR, DW_DLV_ERROR);
|
843
|
+
}
|
844
|
+
}
|
845
|
+
}
|
846
|
+
/* Fetch next section */
|
847
|
+
}
|
848
|
+
}
|
849
|
+
|
850
|
+
/* Free table with section information. */
|
851
|
+
free(sections);
|
852
|
+
if (foundDwarf) {
|
853
|
+
return DW_DLV_OK;
|
854
|
+
}
|
855
|
+
return DW_DLV_NO_ENTRY;
|
856
|
+
}
|
857
|
+
|
858
|
+
#if 0
|
859
|
+
static int
|
860
|
+
all_sig8_bits_zero(Dwarf_Sig8 *val)
|
861
|
+
{
|
862
|
+
unsigned u = 0;
|
863
|
+
for( ; u < sizeof(*val); ++u) {
|
864
|
+
if (val->signature[u] != 0) {
|
865
|
+
return FALSE;
|
866
|
+
}
|
867
|
+
}
|
868
|
+
return TRUE;
|
869
|
+
}
|
870
|
+
#endif /* if 0 */
|
871
|
+
|
872
|
+
/* There is one table per CU and one per TU, and each
|
873
|
+
table refers to the associated other DWARF data
|
874
|
+
for that CU or TU.
|
875
|
+
See DW_SECT_*
|
876
|
+
|
877
|
+
In DWARF4 the type units are in .debug_types
|
878
|
+
In DWARF5 the type units are in .debug_info.
|
879
|
+
*/
|
880
|
+
|
881
|
+
static int
|
882
|
+
load_debugfission_tables(Dwarf_Debug dbg,Dwarf_Error *error)
|
883
|
+
{
|
884
|
+
int i = 0;
|
885
|
+
if (dbg->de_debug_cu_index.dss_size ==0 &&
|
886
|
+
dbg->de_debug_tu_index.dss_size ==0) {
|
887
|
+
/* This is the normal case.
|
888
|
+
No debug fission. Not a .dwp object. */
|
889
|
+
return DW_DLV_NO_ENTRY;
|
890
|
+
}
|
891
|
+
|
892
|
+
for (i = 0; i < 2; ++i) {
|
893
|
+
Dwarf_Xu_Index_Header xuptr = 0;
|
894
|
+
struct Dwarf_Section_s* dwsect = 0;
|
895
|
+
Dwarf_Unsigned version = 0;
|
896
|
+
Dwarf_Unsigned number_of_cols /* L */ = 0;
|
897
|
+
Dwarf_Unsigned number_of_CUs /* N */ = 0;
|
898
|
+
Dwarf_Unsigned number_of_slots /* M */ = 0;
|
899
|
+
const char *secname = 0;
|
900
|
+
int res = 0;
|
901
|
+
const char *type = 0;
|
902
|
+
|
903
|
+
if (i == 0) {
|
904
|
+
dwsect = &dbg->de_debug_cu_index;
|
905
|
+
type = "cu";
|
906
|
+
} else {
|
907
|
+
dwsect = &dbg->de_debug_tu_index;
|
908
|
+
type = "tu";
|
909
|
+
}
|
910
|
+
if ( !dwsect->dss_size ) {
|
911
|
+
continue;
|
912
|
+
}
|
913
|
+
res = dwarf_get_xu_index_header(dbg,type,
|
914
|
+
&xuptr,&version,&number_of_cols,
|
915
|
+
&number_of_CUs,&number_of_slots,
|
916
|
+
&secname,error);
|
917
|
+
if (res == DW_DLV_NO_ENTRY) {
|
918
|
+
continue;
|
919
|
+
}
|
920
|
+
if (res != DW_DLV_OK) {
|
921
|
+
return res;
|
922
|
+
}
|
923
|
+
if (i == 0) {
|
924
|
+
dbg->de_cu_hashindex_data = xuptr;
|
925
|
+
} else {
|
926
|
+
dbg->de_tu_hashindex_data = xuptr;
|
927
|
+
}
|
928
|
+
}
|
929
|
+
return DW_DLV_OK;
|
930
|
+
}
|
931
|
+
|
932
|
+
/*
|
933
|
+
Use a Dwarf_Obj_Access_Interface to kick things off. All other
|
934
|
+
init routines eventually use this one.
|
935
|
+
The returned Dwarf_Debug contains a copy of *obj
|
936
|
+
the callers copy of *obj may be freed whenever the caller
|
937
|
+
wishes.
|
938
|
+
*/
|
939
|
+
int
|
940
|
+
dwarf_object_init(Dwarf_Obj_Access_Interface* obj, Dwarf_Handler errhand,
|
941
|
+
Dwarf_Ptr errarg, Dwarf_Debug* ret_dbg,
|
942
|
+
Dwarf_Error* error)
|
943
|
+
{
|
944
|
+
Dwarf_Debug dbg = 0;
|
945
|
+
int setup_result = DW_DLV_OK;
|
946
|
+
|
947
|
+
dbg = _dwarf_get_debug();
|
948
|
+
if (dbg == NULL) {
|
949
|
+
DWARF_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC, DW_DLV_ERROR);
|
950
|
+
}
|
951
|
+
dbg->de_errhand = errhand;
|
952
|
+
dbg->de_errarg = errarg;
|
953
|
+
dbg->de_frame_rule_initial_value = DW_FRAME_REG_INITIAL_VALUE;
|
954
|
+
dbg->de_frame_reg_rules_entry_count = DW_FRAME_LAST_REG_NUM;
|
955
|
+
#ifdef HAVE_OLD_FRAME_CFA_COL
|
956
|
+
/* DW_FRAME_CFA_COL is really only suitable for old libdwarf frame
|
957
|
+
interfaces and its value of 0 there is only usable where
|
958
|
+
(as in MIPS) register 0 has no value other than 0 so
|
959
|
+
we can use the frame table column 0 for the CFA value
|
960
|
+
(and rely on client software to know when 'register 0'
|
961
|
+
is the cfa and when to just use a value 0 for register 0).
|
962
|
+
*/
|
963
|
+
dbg->de_frame_cfa_col_number = DW_FRAME_CFA_COL;
|
964
|
+
#else
|
965
|
+
dbg->de_frame_cfa_col_number = DW_FRAME_CFA_COL3;
|
966
|
+
#endif
|
967
|
+
dbg->de_frame_same_value_number = DW_FRAME_SAME_VAL;
|
968
|
+
dbg->de_frame_undefined_value_number = DW_FRAME_UNDEFINED_VAL;
|
969
|
+
|
970
|
+
dbg->de_obj_file = obj;
|
971
|
+
|
972
|
+
setup_result = _dwarf_setup(dbg, error);
|
973
|
+
if (setup_result == DW_DLV_OK) {
|
974
|
+
int fission_result = load_debugfission_tables(dbg,error);
|
975
|
+
/* In most cases we get
|
976
|
+
setup_result == DW_DLV_NO_ENTRY here
|
977
|
+
as having debugfission (.dwp objects)
|
978
|
+
is fairly rare. */
|
979
|
+
if (fission_result == DW_DLV_ERROR) {
|
980
|
+
/* Something is very wrong. */
|
981
|
+
setup_result = fission_result;
|
982
|
+
}
|
983
|
+
}
|
984
|
+
if (setup_result != DW_DLV_OK) {
|
985
|
+
int freeresult = 0;
|
986
|
+
/* We cannot use any _dwarf_setup()
|
987
|
+
error here as
|
988
|
+
we are freeing dbg, making that error (setup
|
989
|
+
as part of dbg) stale.
|
990
|
+
Hence we have to make a new error without a dbg.
|
991
|
+
But error might be NULL and the init call
|
992
|
+
error-handler function might be set.
|
993
|
+
*/
|
994
|
+
int myerr = 0;
|
995
|
+
if ( (setup_result == DW_DLV_ERROR) && error ) {
|
996
|
+
/* Preserve our _dwarf_setup error number, but
|
997
|
+
this does not apply if error NULL. */
|
998
|
+
myerr = dwarf_errno(*error);
|
999
|
+
/* deallocate the soon-stale error pointer. */
|
1000
|
+
dwarf_dealloc(dbg,*error,DW_DLA_ERROR);
|
1001
|
+
*error = 0;
|
1002
|
+
}
|
1003
|
+
/* The status we want to return here is of _dwarf_setup,
|
1004
|
+
not of the _dwarf_free_all_of_one_debug(dbg) call.
|
1005
|
+
So use a local status variable for the free. */
|
1006
|
+
freeresult = _dwarf_free_all_of_one_debug(dbg);
|
1007
|
+
dbg = 0;
|
1008
|
+
/* DW_DLV_NO_ENTRY not possible in freeresult */
|
1009
|
+
if (freeresult == DW_DLV_ERROR) {
|
1010
|
+
/* Use the _dwarf_setup error number.
|
1011
|
+
If error is NULL the following will issue
|
1012
|
+
a message on stderr and abort(), as without
|
1013
|
+
dbg there is no error-handler function.
|
1014
|
+
*/
|
1015
|
+
_dwarf_error(NULL,error,DW_DLE_DBG_ALLOC);
|
1016
|
+
return DW_DLV_ERROR;
|
1017
|
+
}
|
1018
|
+
if (setup_result == DW_DLV_ERROR) {
|
1019
|
+
/* Use the _dwarf_setup error number.
|
1020
|
+
If error is NULL the following will issue
|
1021
|
+
a message on stderr and abort(), as without
|
1022
|
+
dbg there is no error-handler function.
|
1023
|
+
*/
|
1024
|
+
_dwarf_error(NULL,error,myerr);
|
1025
|
+
}
|
1026
|
+
return setup_result;
|
1027
|
+
}
|
1028
|
+
dwarf_harmless_init(&dbg->de_harmless_errors,
|
1029
|
+
DW_HARMLESS_ERROR_CIRCULAR_LIST_DEFAULT_SIZE);
|
1030
|
+
*ret_dbg = dbg;
|
1031
|
+
return DW_DLV_OK;
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
|
1035
|
+
/* A finish routine that is completely unaware of ELF.
|
1036
|
+
|
1037
|
+
Frees all memory that was not previously freed by
|
1038
|
+
dwarf_dealloc.
|
1039
|
+
Aside frmo certain categories. */
|
1040
|
+
int
|
1041
|
+
dwarf_object_finish(Dwarf_Debug dbg, Dwarf_Error * error)
|
1042
|
+
{
|
1043
|
+
int res = _dwarf_free_all_of_one_debug(dbg);
|
1044
|
+
if (res == DW_DLV_ERROR) {
|
1045
|
+
DWARF_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC, DW_DLV_ERROR);
|
1046
|
+
}
|
1047
|
+
return res;
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
|
1051
|
+
/* Load the ELF section with the specified index and set its
|
1052
|
+
dss_data pointer to the memory where it was loaded. */
|
1053
|
+
int
|
1054
|
+
_dwarf_load_section(Dwarf_Debug dbg,
|
1055
|
+
struct Dwarf_Section_s *section,
|
1056
|
+
Dwarf_Error * error)
|
1057
|
+
{
|
1058
|
+
int res = DW_DLV_ERROR;
|
1059
|
+
int err = 0;
|
1060
|
+
struct Dwarf_Obj_Access_Interface_s *o = 0;
|
1061
|
+
|
1062
|
+
/* check to see if the section is already loaded */
|
1063
|
+
if (section->dss_data != NULL) {
|
1064
|
+
return DW_DLV_OK;
|
1065
|
+
}
|
1066
|
+
o = dbg->de_obj_file;
|
1067
|
+
/* There is an elf convention that section index 0 is reserved,
|
1068
|
+
and that section is always empty.
|
1069
|
+
Non-elf object formats must honor that by ensuring that
|
1070
|
+
(when they assign numbers to 'sections' or 'section-like-things')
|
1071
|
+
they never assign a real section section-number 0 to dss_index. */
|
1072
|
+
res = o->methods->load_section(
|
1073
|
+
o->object, section->dss_index,
|
1074
|
+
§ion->dss_data, &err);
|
1075
|
+
if (res == DW_DLV_ERROR){
|
1076
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
1077
|
+
}
|
1078
|
+
if (_dwarf_apply_relocs == 0) {
|
1079
|
+
return res;
|
1080
|
+
}
|
1081
|
+
if (section->dss_reloc_size == 0) {
|
1082
|
+
return res;
|
1083
|
+
}
|
1084
|
+
if (!o->methods->relocate_a_section) {
|
1085
|
+
return res;
|
1086
|
+
}
|
1087
|
+
/*apply relocations */
|
1088
|
+
res = o->methods->relocate_a_section( o->object, section->dss_index,
|
1089
|
+
dbg, &err);
|
1090
|
+
if (res == DW_DLV_ERROR) {
|
1091
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
1092
|
+
}
|
1093
|
+
return res;
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
/* This is a hack so clients can verify offsets.
|
1097
|
+
Added April 2005 so that debugger can detect broken offsets
|
1098
|
+
(which happened in an IRIX -64 executable larger than 2GB
|
1099
|
+
using MIPSpro 7.3.1.3 compilers. A couple .debug_pubnames
|
1100
|
+
offsets were wrong.).
|
1101
|
+
*/
|
1102
|
+
int
|
1103
|
+
dwarf_get_section_max_offsets(Dwarf_Debug dbg,
|
1104
|
+
Dwarf_Unsigned * debug_info_size,
|
1105
|
+
Dwarf_Unsigned * debug_abbrev_size,
|
1106
|
+
Dwarf_Unsigned * debug_line_size,
|
1107
|
+
Dwarf_Unsigned * debug_loc_size,
|
1108
|
+
Dwarf_Unsigned * debug_aranges_size,
|
1109
|
+
Dwarf_Unsigned * debug_macinfo_size,
|
1110
|
+
Dwarf_Unsigned * debug_pubnames_size,
|
1111
|
+
Dwarf_Unsigned * debug_str_size,
|
1112
|
+
Dwarf_Unsigned * debug_frame_size,
|
1113
|
+
Dwarf_Unsigned * debug_ranges_size,
|
1114
|
+
Dwarf_Unsigned * debug_typenames_size)
|
1115
|
+
{
|
1116
|
+
*debug_info_size = dbg->de_debug_info.dss_size;
|
1117
|
+
*debug_abbrev_size = dbg->de_debug_abbrev.dss_size;
|
1118
|
+
*debug_line_size = dbg->de_debug_line.dss_size;
|
1119
|
+
*debug_loc_size = dbg->de_debug_loc.dss_size;
|
1120
|
+
*debug_aranges_size = dbg->de_debug_aranges.dss_size;
|
1121
|
+
*debug_macinfo_size = dbg->de_debug_macinfo.dss_size;
|
1122
|
+
*debug_pubnames_size = dbg->de_debug_pubnames.dss_size;
|
1123
|
+
*debug_str_size = dbg->de_debug_str.dss_size;
|
1124
|
+
*debug_frame_size = dbg->de_debug_frame.dss_size;
|
1125
|
+
*debug_ranges_size = dbg->de_debug_ranges.dss_size;
|
1126
|
+
*debug_typenames_size = dbg->de_debug_typenames.dss_size;
|
1127
|
+
return DW_DLV_OK;
|
1128
|
+
}
|
1129
|
+
/* This adds the new types size (new section) to the output data.
|
1130
|
+
Oct 27, 2011. */
|
1131
|
+
int
|
1132
|
+
dwarf_get_section_max_offsets_b(Dwarf_Debug dbg,
|
1133
|
+
Dwarf_Unsigned * debug_info_size,
|
1134
|
+
Dwarf_Unsigned * debug_abbrev_size,
|
1135
|
+
Dwarf_Unsigned * debug_line_size,
|
1136
|
+
Dwarf_Unsigned * debug_loc_size,
|
1137
|
+
Dwarf_Unsigned * debug_aranges_size,
|
1138
|
+
Dwarf_Unsigned * debug_macinfo_size,
|
1139
|
+
Dwarf_Unsigned * debug_pubnames_size,
|
1140
|
+
Dwarf_Unsigned * debug_str_size,
|
1141
|
+
Dwarf_Unsigned * debug_frame_size,
|
1142
|
+
Dwarf_Unsigned * debug_ranges_size,
|
1143
|
+
Dwarf_Unsigned * debug_typenames_size,
|
1144
|
+
Dwarf_Unsigned * debug_types_size)
|
1145
|
+
{
|
1146
|
+
*debug_info_size = dbg->de_debug_info.dss_size;
|
1147
|
+
*debug_abbrev_size = dbg->de_debug_abbrev.dss_size;
|
1148
|
+
*debug_line_size = dbg->de_debug_line.dss_size;
|
1149
|
+
*debug_loc_size = dbg->de_debug_loc.dss_size;
|
1150
|
+
*debug_aranges_size = dbg->de_debug_aranges.dss_size;
|
1151
|
+
*debug_macinfo_size = dbg->de_debug_macinfo.dss_size;
|
1152
|
+
*debug_pubnames_size = dbg->de_debug_pubnames.dss_size;
|
1153
|
+
*debug_str_size = dbg->de_debug_str.dss_size;
|
1154
|
+
*debug_frame_size = dbg->de_debug_frame.dss_size;
|
1155
|
+
*debug_ranges_size = dbg->de_debug_ranges.dss_size;
|
1156
|
+
*debug_typenames_size = dbg->de_debug_typenames.dss_size;
|
1157
|
+
*debug_types_size = dbg->de_debug_types.dss_size;
|
1158
|
+
return DW_DLV_OK;
|
1159
|
+
}
|
1160
|
+
|
1161
|
+
|
1162
|
+
/* Given a section name, get its size and address */
|
1163
|
+
int
|
1164
|
+
dwarf_get_section_info_by_name(Dwarf_Debug dbg,
|
1165
|
+
const char *section_name,
|
1166
|
+
Dwarf_Addr *section_addr,
|
1167
|
+
Dwarf_Unsigned *section_size,
|
1168
|
+
Dwarf_Error * error)
|
1169
|
+
{
|
1170
|
+
struct Dwarf_Obj_Access_Section_s doas;
|
1171
|
+
struct Dwarf_Obj_Access_Interface_s * obj = 0;
|
1172
|
+
Dwarf_Unsigned section_count = 0;
|
1173
|
+
Dwarf_Half section_index = 0;
|
1174
|
+
|
1175
|
+
*section_addr = 0;
|
1176
|
+
*section_size = 0;
|
1177
|
+
|
1178
|
+
obj = dbg->de_obj_file;
|
1179
|
+
if (NULL == obj) {
|
1180
|
+
return DW_DLV_NO_ENTRY;
|
1181
|
+
}
|
1182
|
+
|
1183
|
+
section_count = obj->methods->get_section_count(obj->object);
|
1184
|
+
|
1185
|
+
/* We can skip index 0 when considering ELF files, but not other
|
1186
|
+
object types. */
|
1187
|
+
for (section_index = 0; section_index < section_count;
|
1188
|
+
++section_index) {
|
1189
|
+
int err = 0;
|
1190
|
+
int res = obj->methods->get_section_info(obj->object,
|
1191
|
+
section_index, &doas, &err);
|
1192
|
+
if (res == DW_DLV_ERROR) {
|
1193
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
1194
|
+
}
|
1195
|
+
|
1196
|
+
if (!strcmp(section_name,doas.name)) {
|
1197
|
+
*section_addr = doas.addr;
|
1198
|
+
*section_size = doas.size;
|
1199
|
+
return DW_DLV_OK;
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
return DW_DLV_NO_ENTRY;
|
1204
|
+
}
|
1205
|
+
|
1206
|
+
/* Given a section index, get its size and address */
|
1207
|
+
int
|
1208
|
+
dwarf_get_section_info_by_index(Dwarf_Debug dbg,
|
1209
|
+
int section_index,
|
1210
|
+
const char **section_name,
|
1211
|
+
Dwarf_Addr *section_addr,
|
1212
|
+
Dwarf_Unsigned *section_size,
|
1213
|
+
Dwarf_Error * error)
|
1214
|
+
{
|
1215
|
+
*section_addr = 0;
|
1216
|
+
*section_size = 0;
|
1217
|
+
*section_name = NULL;
|
1218
|
+
|
1219
|
+
/* Check if we have a valid section index */
|
1220
|
+
if (section_index >= 0 && section_index < dwarf_get_section_count(dbg)) {
|
1221
|
+
int res = 0;
|
1222
|
+
int err = 0;
|
1223
|
+
struct Dwarf_Obj_Access_Section_s doas;
|
1224
|
+
struct Dwarf_Obj_Access_Interface_s * obj = dbg->de_obj_file;
|
1225
|
+
if (NULL == obj) {
|
1226
|
+
return DW_DLV_NO_ENTRY;
|
1227
|
+
}
|
1228
|
+
res = obj->methods->get_section_info(obj->object,
|
1229
|
+
section_index, &doas, &err);
|
1230
|
+
if (res == DW_DLV_ERROR){
|
1231
|
+
DWARF_DBG_ERROR(dbg, err, DW_DLV_ERROR);
|
1232
|
+
}
|
1233
|
+
|
1234
|
+
*section_addr = doas.addr;
|
1235
|
+
*section_size = doas.size;
|
1236
|
+
*section_name = doas.name;
|
1237
|
+
return DW_DLV_OK;
|
1238
|
+
}
|
1239
|
+
return DW_DLV_NO_ENTRY;
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
/* Get section count */
|
1243
|
+
int
|
1244
|
+
dwarf_get_section_count(Dwarf_Debug dbg)
|
1245
|
+
{
|
1246
|
+
struct Dwarf_Obj_Access_Interface_s * obj = dbg->de_obj_file;
|
1247
|
+
if (NULL == obj) {
|
1248
|
+
return DW_DLV_NO_ENTRY;
|
1249
|
+
}
|
1250
|
+
return obj->methods->get_section_count(obj->object);
|
1251
|
+
}
|
1252
|
+
|
1253
|
+
Dwarf_Cmdline_Options dwarf_cmdline_options = {
|
1254
|
+
FALSE /* Use quiet mode by default. */
|
1255
|
+
};
|
1256
|
+
|
1257
|
+
/* Lets libdwarf reflect a command line option, so we can get details
|
1258
|
+
of some errors printed using libdwarf-internal information. */
|
1259
|
+
void
|
1260
|
+
dwarf_record_cmdline_options(Dwarf_Cmdline_Options options)
|
1261
|
+
{
|
1262
|
+
dwarf_cmdline_options = options;
|
1263
|
+
}
|