rdwarf 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +28 -0
  6. data/README.md +39 -0
  7. data/Rakefile +8 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +7 -0
  10. data/ext/rdwarf/depend +5 -0
  11. data/ext/rdwarf/extconf.rb +29 -0
  12. data/ext/rdwarf/libdwarf/CHANGES +102 -0
  13. data/ext/rdwarf/libdwarf/CODINGSTYLE +71 -0
  14. data/ext/rdwarf/libdwarf/COPYING +28 -0
  15. data/ext/rdwarf/libdwarf/ChangeLog +619 -0
  16. data/ext/rdwarf/libdwarf/ChangeLog2006 +835 -0
  17. data/ext/rdwarf/libdwarf/ChangeLog2007 +217 -0
  18. data/ext/rdwarf/libdwarf/ChangeLog2008 +263 -0
  19. data/ext/rdwarf/libdwarf/ChangeLog2009 +348 -0
  20. data/ext/rdwarf/libdwarf/ChangeLog2010 +175 -0
  21. data/ext/rdwarf/libdwarf/ChangeLog2011 +297 -0
  22. data/ext/rdwarf/libdwarf/ChangeLog2012 +131 -0
  23. data/ext/rdwarf/libdwarf/ChangeLog2013 +238 -0
  24. data/ext/rdwarf/libdwarf/ChangeLog2014 +399 -0
  25. data/ext/rdwarf/libdwarf/LGPL.txt +504 -0
  26. data/ext/rdwarf/libdwarf/LIBDWARFCOPYRIGHT +40 -0
  27. data/ext/rdwarf/libdwarf/Makefile.in +220 -0
  28. data/ext/rdwarf/libdwarf/NEWS +535 -0
  29. data/ext/rdwarf/libdwarf/README +235 -0
  30. data/ext/rdwarf/libdwarf/checkexamples.c +1179 -0
  31. data/ext/rdwarf/libdwarf/cmplrs/dwarf_addr_finder.h +55 -0
  32. data/ext/rdwarf/libdwarf/common.c +62 -0
  33. data/ext/rdwarf/libdwarf/common.h +38 -0
  34. data/ext/rdwarf/libdwarf/config.h.in +146 -0
  35. data/ext/rdwarf/libdwarf/configure +5581 -0
  36. data/ext/rdwarf/libdwarf/configure.in +167 -0
  37. data/ext/rdwarf/libdwarf/dw-linetableheader.txt +39 -0
  38. data/ext/rdwarf/libdwarf/dwarf.h +1342 -0
  39. data/ext/rdwarf/libdwarf/dwarf_abbrev.c +291 -0
  40. data/ext/rdwarf/libdwarf/dwarf_abbrev.h +45 -0
  41. data/ext/rdwarf/libdwarf/dwarf_addr_finder.c +676 -0
  42. data/ext/rdwarf/libdwarf/dwarf_alloc.c +685 -0
  43. data/ext/rdwarf/libdwarf/dwarf_alloc.h +38 -0
  44. data/ext/rdwarf/libdwarf/dwarf_arange.c +595 -0
  45. data/ext/rdwarf/libdwarf/dwarf_arange.h +62 -0
  46. data/ext/rdwarf/libdwarf/dwarf_base_types.h +157 -0
  47. data/ext/rdwarf/libdwarf/dwarf_die_deliv.c +1802 -0
  48. data/ext/rdwarf/libdwarf/dwarf_die_deliv.h +46 -0
  49. data/ext/rdwarf/libdwarf/dwarf_elf_access.c +1348 -0
  50. data/ext/rdwarf/libdwarf/dwarf_elf_access.h +46 -0
  51. data/ext/rdwarf/libdwarf/dwarf_error.c +492 -0
  52. data/ext/rdwarf/libdwarf/dwarf_error.h +53 -0
  53. data/ext/rdwarf/libdwarf/dwarf_form.c +1302 -0
  54. data/ext/rdwarf/libdwarf/dwarf_frame.c +2454 -0
  55. data/ext/rdwarf/libdwarf/dwarf_frame.h +418 -0
  56. data/ext/rdwarf/libdwarf/dwarf_frame2.c +1533 -0
  57. data/ext/rdwarf/libdwarf/dwarf_frame3.c +282 -0
  58. data/ext/rdwarf/libdwarf/dwarf_funcs.c +123 -0
  59. data/ext/rdwarf/libdwarf/dwarf_funcs.h +33 -0
  60. data/ext/rdwarf/libdwarf/dwarf_gdbindex.c +520 -0
  61. data/ext/rdwarf/libdwarf/dwarf_gdbindex.h +97 -0
  62. data/ext/rdwarf/libdwarf/dwarf_global.c +612 -0
  63. data/ext/rdwarf/libdwarf/dwarf_global.h +117 -0
  64. data/ext/rdwarf/libdwarf/dwarf_harmless.c +228 -0
  65. data/ext/rdwarf/libdwarf/dwarf_harmless.h +31 -0
  66. data/ext/rdwarf/libdwarf/dwarf_incl.h +61 -0
  67. data/ext/rdwarf/libdwarf/dwarf_init_finish.c +1263 -0
  68. data/ext/rdwarf/libdwarf/dwarf_leb.c +159 -0
  69. data/ext/rdwarf/libdwarf/dwarf_line.c +1822 -0
  70. data/ext/rdwarf/libdwarf/dwarf_line.h +446 -0
  71. data/ext/rdwarf/libdwarf/dwarf_line2.c +98 -0
  72. data/ext/rdwarf/libdwarf/dwarf_line_table_reader_common.c +1583 -0
  73. data/ext/rdwarf/libdwarf/dwarf_loc.c +1525 -0
  74. data/ext/rdwarf/libdwarf/dwarf_loc.h +149 -0
  75. data/ext/rdwarf/libdwarf/dwarf_loc2.c +833 -0
  76. data/ext/rdwarf/libdwarf/dwarf_macro.c +479 -0
  77. data/ext/rdwarf/libdwarf/dwarf_macro.h +35 -0
  78. data/ext/rdwarf/libdwarf/dwarf_opaque.h +778 -0
  79. data/ext/rdwarf/libdwarf/dwarf_original_elf_init.c +219 -0
  80. data/ext/rdwarf/libdwarf/dwarf_print_lines.c +631 -0
  81. data/ext/rdwarf/libdwarf/dwarf_pubtypes.c +132 -0
  82. data/ext/rdwarf/libdwarf/dwarf_query.c +1594 -0
  83. data/ext/rdwarf/libdwarf/dwarf_ranges.c +194 -0
  84. data/ext/rdwarf/libdwarf/dwarf_reloc_arm.h +308 -0
  85. data/ext/rdwarf/libdwarf/dwarf_reloc_mips.h +117 -0
  86. data/ext/rdwarf/libdwarf/dwarf_reloc_ppc.h +242 -0
  87. data/ext/rdwarf/libdwarf/dwarf_reloc_ppc64.h +272 -0
  88. data/ext/rdwarf/libdwarf/dwarf_reloc_x86_64.h +127 -0
  89. data/ext/rdwarf/libdwarf/dwarf_sort_line.c +665 -0
  90. data/ext/rdwarf/libdwarf/dwarf_string.c +82 -0
  91. data/ext/rdwarf/libdwarf/dwarf_stubs.c +38 -0
  92. data/ext/rdwarf/libdwarf/dwarf_tied.c +423 -0
  93. data/ext/rdwarf/libdwarf/dwarf_tsearch.h +125 -0
  94. data/ext/rdwarf/libdwarf/dwarf_tsearchhash.c +675 -0
  95. data/ext/rdwarf/libdwarf/dwarf_types.c +121 -0
  96. data/ext/rdwarf/libdwarf/dwarf_types.h +32 -0
  97. data/ext/rdwarf/libdwarf/dwarf_util.c +913 -0
  98. data/ext/rdwarf/libdwarf/dwarf_util.h +324 -0
  99. data/ext/rdwarf/libdwarf/dwarf_vars.c +125 -0
  100. data/ext/rdwarf/libdwarf/dwarf_vars.h +29 -0
  101. data/ext/rdwarf/libdwarf/dwarf_weaks.c +123 -0
  102. data/ext/rdwarf/libdwarf/dwarf_weaks.h +29 -0
  103. data/ext/rdwarf/libdwarf/dwarf_xu_index.c +579 -0
  104. data/ext/rdwarf/libdwarf/dwarf_xu_index.h +68 -0
  105. data/ext/rdwarf/libdwarf/dwgetopt.c +181 -0
  106. data/ext/rdwarf/libdwarf/dwgetopt.h +51 -0
  107. data/ext/rdwarf/libdwarf/gennames.c +531 -0
  108. data/ext/rdwarf/libdwarf/install.sh +119 -0
  109. data/ext/rdwarf/libdwarf/libdwarf.h.in +3746 -0
  110. data/ext/rdwarf/libdwarf/libdwarf2.1.mm +9805 -0
  111. data/ext/rdwarf/libdwarf/libdwarf2.1.pdf +0 -0
  112. data/ext/rdwarf/libdwarf/libdwarf2p.1.mm +2807 -0
  113. data/ext/rdwarf/libdwarf/libdwarf2p.1.pdf +0 -0
  114. data/ext/rdwarf/libdwarf/libdwarfdefs.h +81 -0
  115. data/ext/rdwarf/libdwarf/malloc_check.c +327 -0
  116. data/ext/rdwarf/libdwarf/malloc_check.h +52 -0
  117. data/ext/rdwarf/libdwarf/mips_extensions.mm +1266 -0
  118. data/ext/rdwarf/libdwarf/mips_extensions.pdf +0 -0
  119. data/ext/rdwarf/libdwarf/pro_alloc.c +179 -0
  120. data/ext/rdwarf/libdwarf/pro_alloc.h +33 -0
  121. data/ext/rdwarf/libdwarf/pro_arange.c +310 -0
  122. data/ext/rdwarf/libdwarf/pro_arange.h +51 -0
  123. data/ext/rdwarf/libdwarf/pro_die.c +431 -0
  124. data/ext/rdwarf/libdwarf/pro_die.h +59 -0
  125. data/ext/rdwarf/libdwarf/pro_encode_nm.c +108 -0
  126. data/ext/rdwarf/libdwarf/pro_encode_nm.h +39 -0
  127. data/ext/rdwarf/libdwarf/pro_error.c +96 -0
  128. data/ext/rdwarf/libdwarf/pro_error.h +43 -0
  129. data/ext/rdwarf/libdwarf/pro_expr.c +575 -0
  130. data/ext/rdwarf/libdwarf/pro_expr.h +36 -0
  131. data/ext/rdwarf/libdwarf/pro_finish.c +45 -0
  132. data/ext/rdwarf/libdwarf/pro_forms.c +1271 -0
  133. data/ext/rdwarf/libdwarf/pro_frame.c +572 -0
  134. data/ext/rdwarf/libdwarf/pro_frame.h +120 -0
  135. data/ext/rdwarf/libdwarf/pro_funcs.c +50 -0
  136. data/ext/rdwarf/libdwarf/pro_incl.h +91 -0
  137. data/ext/rdwarf/libdwarf/pro_init.c +327 -0
  138. data/ext/rdwarf/libdwarf/pro_line.c +373 -0
  139. data/ext/rdwarf/libdwarf/pro_line.h +112 -0
  140. data/ext/rdwarf/libdwarf/pro_macinfo.c +457 -0
  141. data/ext/rdwarf/libdwarf/pro_macinfo.h +31 -0
  142. data/ext/rdwarf/libdwarf/pro_opaque.h +513 -0
  143. data/ext/rdwarf/libdwarf/pro_pubnames.c +60 -0
  144. data/ext/rdwarf/libdwarf/pro_reloc.c +253 -0
  145. data/ext/rdwarf/libdwarf/pro_reloc.h +38 -0
  146. data/ext/rdwarf/libdwarf/pro_reloc_stream.c +256 -0
  147. data/ext/rdwarf/libdwarf/pro_reloc_stream.h +52 -0
  148. data/ext/rdwarf/libdwarf/pro_reloc_symbolic.c +245 -0
  149. data/ext/rdwarf/libdwarf/pro_reloc_symbolic.h +45 -0
  150. data/ext/rdwarf/libdwarf/pro_section.c +2233 -0
  151. data/ext/rdwarf/libdwarf/pro_section.h +100 -0
  152. data/ext/rdwarf/libdwarf/pro_types.c +274 -0
  153. data/ext/rdwarf/libdwarf/pro_types.h +34 -0
  154. data/ext/rdwarf/libdwarf/pro_util.h +38 -0
  155. data/ext/rdwarf/libdwarf/pro_vars.c +52 -0
  156. data/ext/rdwarf/libdwarf/pro_weaks.c +51 -0
  157. data/ext/rdwarf/rdwarf.c +765 -0
  158. data/ext/rdwarf/rdwarf.h +52 -0
  159. data/ext/rdwarf/rdwarf_names_gen.rb +109 -0
  160. data/lib/rdwarf.rb +181 -0
  161. data/lib/rdwarf/version.rb +3 -0
  162. data/rdwarf.gemspec +30 -0
  163. metadata +251 -0
@@ -0,0 +1,123 @@
1
+ /*
2
+
3
+ Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright (C) 2009-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
+ #include "config.h"
29
+ #include "dwarf_incl.h"
30
+ #include <stdio.h>
31
+ #include "dwarf_weaks.h"
32
+ #include "dwarf_global.h"
33
+
34
+ int
35
+ dwarf_get_weaks(Dwarf_Debug dbg,
36
+ Dwarf_Weak ** weaks,
37
+ Dwarf_Signed * ret_weak_count, Dwarf_Error * error)
38
+ {
39
+ int res = _dwarf_load_section(dbg, &dbg->de_debug_weaknames,error);
40
+ if (res != DW_DLV_OK) {
41
+ return res;
42
+ }
43
+ if (!dbg->de_debug_weaknames.dss_size) {
44
+ return (DW_DLV_NO_ENTRY);
45
+ }
46
+
47
+
48
+ return _dwarf_internal_get_pubnames_like_data(dbg,
49
+ dbg->de_debug_weaknames.dss_data,
50
+ dbg->de_debug_weaknames.dss_size,
51
+ (Dwarf_Global **) weaks, /* Type punning for sections
52
+ with identical format. */
53
+ ret_weak_count,
54
+ error,
55
+ DW_DLA_WEAK_CONTEXT,
56
+ DW_DLA_WEAK,
57
+ DW_DLE_DEBUG_WEAKNAMES_LENGTH_BAD,
58
+ DW_DLE_DEBUG_WEAKNAMES_VERSION_ERROR);
59
+ }
60
+
61
+ /* Deallocating fully requires deallocating the list
62
+ and all entries. But some internal data is
63
+ not exposed, so we need a function with internal knowledge.
64
+ */
65
+
66
+ void
67
+ dwarf_weaks_dealloc(Dwarf_Debug dbg, Dwarf_Weak * dwgl,
68
+ Dwarf_Signed count)
69
+ {
70
+ _dwarf_internal_globals_dealloc(dbg, (Dwarf_Global *) dwgl,
71
+ count,
72
+ DW_DLA_WEAK_CONTEXT,
73
+ DW_DLA_WEAK, DW_DLA_LIST);
74
+ return;
75
+ }
76
+
77
+
78
+
79
+ int
80
+ dwarf_weakname(Dwarf_Weak weak_in, char **ret_name, Dwarf_Error * error)
81
+ {
82
+ Dwarf_Global weak = (Dwarf_Global) weak_in;
83
+
84
+ if (weak == NULL) {
85
+ _dwarf_error(NULL, error, DW_DLE_WEAK_NULL);
86
+ return (DW_DLV_ERROR);
87
+ }
88
+ *ret_name = (char *) (weak->gl_name);
89
+ return DW_DLV_OK;
90
+ }
91
+
92
+
93
+ int
94
+ dwarf_weak_die_offset(Dwarf_Weak weak_in,
95
+ Dwarf_Off * weak_off, Dwarf_Error * error)
96
+ {
97
+ Dwarf_Global weak = (Dwarf_Global) weak_in;
98
+
99
+ return dwarf_global_die_offset(weak, weak_off, error);
100
+ }
101
+
102
+
103
+ int
104
+ dwarf_weak_cu_offset(Dwarf_Weak weak_in,
105
+ Dwarf_Off * weak_off, Dwarf_Error * error)
106
+ {
107
+ Dwarf_Global weak = (Dwarf_Global) weak_in;
108
+
109
+ return dwarf_global_cu_offset(weak, weak_off, error);
110
+ }
111
+
112
+
113
+ int
114
+ dwarf_weak_name_offsets(Dwarf_Weak weak_in,
115
+ char **weak_name,
116
+ Dwarf_Off * die_offset,
117
+ Dwarf_Off * cu_offset, Dwarf_Error * error)
118
+ {
119
+ Dwarf_Global weak = (Dwarf_Global) weak_in;
120
+
121
+ return dwarf_global_name_offsets(weak,
122
+ weak_name, die_offset, cu_offset, error);
123
+ }
@@ -0,0 +1,29 @@
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
+ typedef struct Dwarf_Weak_Context_s *Dwarf_Weak_Context;
28
+
29
+ /* struct never completed: see dwarf_global.h */
@@ -0,0 +1,579 @@
1
+ /*
2
+ Copyright (C) 2014-2015 David Anderson. All Rights Reserved.
3
+
4
+ This program is free software; you can redistribute it and/or modify it
5
+ under the terms of version 2.1 of the GNU Lesser General Public License
6
+ as published by the Free Software Foundation.
7
+
8
+ This program is distributed in the hope that it would be useful, but
9
+ WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
+
12
+ Further, this software is distributed without any warranty that it is
13
+ free of the rightful claim of any third person regarding infringement
14
+ or the like. Any license provided herein, whether implied or
15
+ otherwise, applies only to this software file. Patent licenses, if
16
+ any, provided herein do not apply to combinations of this program with
17
+ other software, or any other product whatsoever.
18
+
19
+ You should have received a copy of the GNU Lesser General Public
20
+ License along with this program; if not, write the Free Software
21
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
22
+ USA.
23
+
24
+ */
25
+
26
+ /* The file and functions have 'xu' because
27
+ the .debug_cu_index and .debug_tu_index
28
+ sections have the same layout and this deals with both.
29
+
30
+ This is DebugFission, part of DWARF5.
31
+
32
+ It allows properly reading a .dwp object file
33
+ with debug-information (no code).
34
+ */
35
+
36
+
37
+
38
+ #include "config.h"
39
+ #include "dwarf_incl.h"
40
+ #include <stdio.h>
41
+ #include <stdlib.h>
42
+ #include "dwarf_xu_index.h"
43
+
44
+ #define HASHSIGNATURELEN 8
45
+ #define LEN32BIT 4
46
+
47
+ #define TRUE 1
48
+ #define FALSE 0
49
+
50
+ int
51
+ dwarf_get_xu_index_header(Dwarf_Debug dbg,
52
+ /* Pass in section_type "tu" or "cu" */
53
+ const char * section_type,
54
+ Dwarf_Xu_Index_Header * xuptr,
55
+ Dwarf_Unsigned * version,
56
+ Dwarf_Unsigned * number_of_columns, /* L */
57
+ Dwarf_Unsigned * number_of_CUs, /* N */
58
+ Dwarf_Unsigned * number_of_slots, /* M */
59
+ const char ** section_name,
60
+ Dwarf_Error * error)
61
+ {
62
+ Dwarf_Xu_Index_Header indexptr = 0;
63
+ int res = DW_DLV_ERROR;
64
+ struct Dwarf_Section_s *sect = 0;
65
+ Dwarf_Unsigned local_version = 0;
66
+ Dwarf_Unsigned num_col = 0;
67
+ Dwarf_Unsigned num_CUs = 0;
68
+ Dwarf_Unsigned num_slots = 0;
69
+ Dwarf_Small *data = 0;
70
+ Dwarf_Unsigned tables_end_offset = 0;
71
+ Dwarf_Unsigned hash_tab_offset = 0;
72
+ Dwarf_Unsigned indexes_tab_offset = 0;
73
+ Dwarf_Unsigned section_offsets_tab_offset = 0;
74
+ Dwarf_Unsigned section_sizes_tab_offset = 0;
75
+ unsigned datalen32 = LEN32BIT;
76
+
77
+ if (!strcmp(section_type,"cu") ) {
78
+ sect = &dbg->de_debug_cu_index;
79
+ } else if (!strcmp(section_type,"tu") ) {
80
+ sect = &dbg->de_debug_tu_index;
81
+ } else {
82
+ _dwarf_error(dbg, error, DW_DLE_XU_TYPE_ARG_ERROR);
83
+ return DW_DLV_ERROR;
84
+ }
85
+ if (!sect->dss_size) {
86
+ return DW_DLV_NO_ENTRY;
87
+ }
88
+
89
+ if (!sect->dss_data) {
90
+ res = _dwarf_load_section(dbg, sect,error);
91
+ if (res != DW_DLV_OK) {
92
+ return res;
93
+ }
94
+ }
95
+
96
+ data = sect->dss_data;
97
+
98
+ if (sect->dss_size < (4*datalen32) ) {
99
+ _dwarf_error(dbg, error, DW_DLE_ERRONEOUS_GDB_INDEX_SECTION);
100
+ return (DW_DLV_ERROR);
101
+ }
102
+ READ_UNALIGNED(dbg,local_version, Dwarf_Unsigned,
103
+ data,datalen32);
104
+ data += datalen32;
105
+ READ_UNALIGNED(dbg,num_col, Dwarf_Unsigned,
106
+ data,datalen32);
107
+ data += datalen32;
108
+ READ_UNALIGNED(dbg,num_CUs, Dwarf_Unsigned,
109
+ data,datalen32);
110
+ data += datalen32;
111
+ READ_UNALIGNED(dbg,num_slots, Dwarf_Unsigned,
112
+ data,datalen32);
113
+ data += datalen32;
114
+ hash_tab_offset = datalen32*4;
115
+ indexes_tab_offset = hash_tab_offset + (num_slots * HASHSIGNATURELEN);
116
+ section_offsets_tab_offset = indexes_tab_offset +
117
+ (num_slots *datalen32);
118
+
119
+ section_sizes_tab_offset = section_offsets_tab_offset +
120
+ ((num_CUs +1) *num_col* datalen32) ;
121
+ tables_end_offset = section_sizes_tab_offset +
122
+ ((num_CUs ) *num_col* datalen32);
123
+
124
+ if ( tables_end_offset > sect->dss_size) {
125
+ /* Something is badly wrong here. */
126
+ _dwarf_error(dbg, error, DW_DLE_ERRONEOUS_GDB_INDEX_SECTION);
127
+ return (DW_DLV_ERROR);
128
+ }
129
+
130
+
131
+ indexptr = (Dwarf_Xu_Index_Header)_dwarf_get_alloc(dbg,DW_DLA_XU_INDEX,1);
132
+ if (indexptr == NULL) {
133
+ _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
134
+ return (DW_DLV_ERROR);
135
+ }
136
+ strcpy(indexptr->gx_type,section_type);
137
+ indexptr->gx_dbg = dbg;
138
+ indexptr->gx_section_length = sect->dss_size;
139
+ indexptr->gx_section_data = sect->dss_data;
140
+ indexptr->gx_section_name = sect->dss_name;
141
+ indexptr->gx_version = local_version;
142
+ indexptr->gx_column_count_sections = num_col;
143
+ indexptr->gx_units_in_index = num_CUs;
144
+ indexptr->gx_slots_in_hash = num_slots;
145
+ indexptr->gx_hash_table_offset = hash_tab_offset;
146
+ indexptr->gx_index_table_offset = indexes_tab_offset;
147
+ indexptr->gx_section_offsets_offset = section_offsets_tab_offset;
148
+ indexptr->gx_section_sizes_offset = section_sizes_tab_offset;
149
+
150
+ *xuptr = indexptr;
151
+ *version = indexptr->gx_version;
152
+ *number_of_columns = indexptr->gx_column_count_sections;
153
+ *number_of_CUs = indexptr->gx_units_in_index;
154
+ *number_of_slots = indexptr->gx_slots_in_hash;
155
+ *section_name = indexptr->gx_section_name;
156
+ return DW_DLV_OK;
157
+ }
158
+
159
+
160
+
161
+ int dwarf_get_xu_index_section_type(Dwarf_Xu_Index_Header xuhdr,
162
+ /* the function returns a pointer to
163
+ the immutable string "tu" or "cu" via this arg. Do not free. */
164
+ const char ** typename,
165
+ /* the function returns a pointer to
166
+ the immutable section name. Do not free.
167
+ .debug_cu_index or .debug_tu_index */
168
+ const char ** sectionname,
169
+ Dwarf_Error * err)
170
+ {
171
+ *typename = &xuhdr->gx_type[0];
172
+ *sectionname = xuhdr->gx_section_name;
173
+ return DW_DLV_OK;
174
+ }
175
+
176
+ /* Index values 0 to M-1 are valid. */
177
+ int dwarf_get_xu_hash_entry(Dwarf_Xu_Index_Header xuhdr,
178
+ Dwarf_Unsigned index,
179
+ /* returns the hash value. 64 bits. */
180
+ Dwarf_Sig8 * hash_value,
181
+
182
+ /* returns the index into rows of offset/size tables. */
183
+ Dwarf_Unsigned * index_to_sections,
184
+ Dwarf_Error * err)
185
+ {
186
+ Dwarf_Debug dbg = xuhdr->gx_dbg;
187
+ Dwarf_Small *hashtab = xuhdr->gx_section_data +
188
+ xuhdr->gx_hash_table_offset;
189
+ Dwarf_Small *indextab = xuhdr->gx_section_data +
190
+ xuhdr->gx_index_table_offset;
191
+ Dwarf_Small *indexentry = 0;
192
+ Dwarf_Small *hashentry = 0;
193
+ Dwarf_Sig8 hashval;
194
+ Dwarf_Unsigned indexval = 0;
195
+
196
+ memset(&hashval,0,sizeof(hashval));
197
+ if (xuhdr->gx_slots_in_hash > 0) {
198
+ if (index >= xuhdr->gx_slots_in_hash) {
199
+ _dwarf_error(dbg, err, DW_DLE_XU_HASH_ROW_ERROR);
200
+ return DW_DLV_ERROR;
201
+ }
202
+ hashentry = hashtab + (index * HASHSIGNATURELEN);
203
+ memcpy(&hashval,hashentry,sizeof(hashval));
204
+ } else {
205
+ _dwarf_error(dbg, err, DW_DLE_XU_HASH_ROW_ERROR);
206
+ return DW_DLV_ERROR;
207
+ }
208
+
209
+ indexentry = indextab + (index * LEN32BIT);
210
+ memcpy(hash_value,&hashval,sizeof(hashval));
211
+
212
+ READ_UNALIGNED(dbg,indexval,Dwarf_Unsigned, indexentry,
213
+ LEN32BIT);
214
+ if (indexval > xuhdr->gx_units_in_index) {
215
+ _dwarf_error(dbg, err, DW_DLE_XU_HASH_INDEX_ERROR);
216
+ return DW_DLV_ERROR;
217
+ }
218
+
219
+ *index_to_sections = indexval;
220
+ return DW_DLV_OK;
221
+ }
222
+
223
+
224
+ static const char * dwp_secnames[] = {
225
+ "No name for zero",
226
+ "DW_SECT_INFO" /* 1 */ /*".debug_info.dwo"*/,
227
+ "DW_SECT_TYPES" /* 2 */ /*".debug_types.dwo"*/,
228
+ "DW_SECT_ABBREV" /* 3 */ /*".debug_abbrev.dwo"*/,
229
+ "DW_SECT_LINE" /* 4 */ /*".debug_line.dwo"*/,
230
+ "DW_SECT_LOC" /* 5 */ /*".debug_loc.dwo"*/,
231
+ "DW_SECT_STR_OFFSETS" /* 6 */ /*".debug_str_offsets.dwo"*/,
232
+ "DW_SECT_MACINFO" /* 7 */ /*".debug_macinfo.dwo"*/,
233
+ "DW_SECT_MACRO" /* 8 */ /*".debug_macro.dwo"*/,
234
+ "No name > 8",
235
+ };
236
+
237
+ /* Row 0 of the Table of Section Offsets,
238
+ columns 0 to L-1, are the section id's,
239
+ and names, such as DW_SECT_INFO (ie, 1) */
240
+ int
241
+ dwarf_get_xu_section_names(Dwarf_Xu_Index_Header xuhdr,
242
+ Dwarf_Unsigned column_index,
243
+ Dwarf_Unsigned* number,
244
+ const char ** name,
245
+ Dwarf_Error * err)
246
+ {
247
+ Dwarf_Unsigned sec_num = 0;
248
+ Dwarf_Debug dbg = xuhdr->gx_dbg;
249
+ Dwarf_Small *namerow = xuhdr->gx_section_offsets_offset +
250
+ xuhdr->gx_section_data;
251
+ Dwarf_Small *nameloc = 0;
252
+ if( column_index >= xuhdr->gx_column_count_sections) {
253
+ _dwarf_error(dbg, err, DW_DLE_XU_NAME_COL_ERROR);
254
+ return DW_DLV_ERROR;
255
+ }
256
+ nameloc = namerow + LEN32BIT *column_index;
257
+ READ_UNALIGNED(dbg,sec_num,Dwarf_Unsigned, nameloc,
258
+ LEN32BIT);
259
+ if (sec_num > DW_SECT_MACRO) {
260
+ _dwarf_error(dbg, err, DW_DLE_XU_NAME_COL_ERROR);
261
+ return DW_DLV_ERROR;
262
+ }
263
+ if (sec_num < 1) {
264
+ return DW_DLV_NO_ENTRY;
265
+ }
266
+ *number = sec_num;
267
+ *name = dwp_secnames[sec_num];
268
+ return DW_DLV_OK;
269
+ }
270
+
271
+
272
+ /* Rows 1 to N
273
+ col 0 to L-1
274
+ are section offset and length values from
275
+ the Table of Section Offsets and Table of Section Sizes. */
276
+ int
277
+ dwarf_get_xu_section_offset(Dwarf_Xu_Index_Header xuhdr,
278
+ Dwarf_Unsigned row_index,
279
+ Dwarf_Unsigned column_index,
280
+ Dwarf_Unsigned* sec_offset,
281
+ Dwarf_Unsigned* sec_size,
282
+ Dwarf_Error * err)
283
+ {
284
+ Dwarf_Debug dbg = xuhdr->gx_dbg;
285
+ /* get to base of tables first. */
286
+ Dwarf_Small *offsetrow = xuhdr->gx_section_offsets_offset +
287
+ xuhdr->gx_section_data;
288
+ Dwarf_Small *sizerow = xuhdr->gx_section_sizes_offset +
289
+ xuhdr->gx_section_data;
290
+ Dwarf_Small *offsetentry = 0;
291
+ Dwarf_Small *sizeentry = 0;
292
+ Dwarf_Unsigned offset = 0;
293
+ Dwarf_Unsigned size = 0;
294
+ Dwarf_Unsigned column_count = xuhdr->gx_column_count_sections;
295
+
296
+ if( row_index > xuhdr->gx_units_in_index) {
297
+ _dwarf_error(dbg, err, DW_DLE_XU_NAME_COL_ERROR);
298
+ return DW_DLV_ERROR;
299
+ }
300
+ if( row_index < 1 ) {
301
+ _dwarf_error(dbg, err, DW_DLE_XU_NAME_COL_ERROR);
302
+ return DW_DLV_ERROR;
303
+ }
304
+
305
+ if( column_index >= xuhdr->gx_column_count_sections) {
306
+ _dwarf_error(dbg, err, DW_DLE_XU_NAME_COL_ERROR);
307
+ return DW_DLV_ERROR;
308
+ }
309
+ offsetrow = offsetrow + (row_index*column_count * LEN32BIT);
310
+ offsetentry = offsetrow + (column_index * LEN32BIT);
311
+
312
+ sizerow = sizerow + ((row_index-1)*column_count * LEN32BIT);
313
+ sizeentry = sizerow + (column_index * LEN32BIT);
314
+
315
+ READ_UNALIGNED(dbg,offset,Dwarf_Unsigned, offsetentry,
316
+ LEN32BIT);
317
+ READ_UNALIGNED(dbg,size,Dwarf_Unsigned, sizeentry,
318
+ LEN32BIT);
319
+ *sec_offset = offset;
320
+ *sec_size = size;
321
+ return DW_DLV_OK;
322
+ }
323
+
324
+ /* zerohashkey used as all-zero-bits for comparison. */
325
+ static Dwarf_Sig8 zerohashkey;
326
+
327
+ static int
328
+ _dwarf_search_fission_for_key(Dwarf_Debug dbg,
329
+ Dwarf_Xu_Index_Header xuhdr,
330
+ Dwarf_Sig8 *key_in,
331
+ Dwarf_Unsigned * percu_index_out,
332
+ Dwarf_Error *error)
333
+ {
334
+ Dwarf_Unsigned key = 0;
335
+ Dwarf_Unsigned primary_hash = 0;
336
+ Dwarf_Unsigned hashprime = 0;
337
+ Dwarf_Unsigned slots = xuhdr->gx_slots_in_hash;
338
+ Dwarf_Unsigned mask = slots -1;
339
+ Dwarf_Sig8 hashentry_key;
340
+ Dwarf_Unsigned percu_index = 0;
341
+
342
+ key = *(Dwarf_Unsigned *)(key_in);
343
+ primary_hash = key & mask;
344
+ hashprime = (((key >>32) &mask) |1);
345
+ while (1) {
346
+ int res = dwarf_get_xu_hash_entry(xuhdr,
347
+ primary_hash,&hashentry_key,
348
+ &percu_index,error);
349
+ if (res != DW_DLV_OK) {
350
+ return res;
351
+ }
352
+ if (percu_index == 0 &&
353
+ !memcmp(&hashentry_key,&zerohashkey,sizeof(Dwarf_Sig8))) {
354
+ return DW_DLV_NO_ENTRY;
355
+ }
356
+ if (!memcmp(key_in,&hashentry_key,sizeof(Dwarf_Sig8))) {
357
+ /* FOUND */
358
+ *percu_index_out = percu_index;
359
+ return DW_DLV_OK;
360
+ }
361
+ primary_hash = (primary_hash + hashprime) % slots;
362
+ }
363
+ /* ASSERT: Cannot get here. */
364
+ return DW_DLV_NO_ENTRY;
365
+ }
366
+
367
+ /* Slow. Consider tsearch. */
368
+ /* For type units and for CUs. */
369
+ static int
370
+ _dwarf_search_fission_for_offset(Dwarf_Debug dbg,
371
+ Dwarf_Xu_Index_Header xuhdr,
372
+ Dwarf_Unsigned offset,
373
+ Dwarf_Unsigned dfp_sect_num, /* DW_SECT_INFO or TYPES */
374
+ Dwarf_Unsigned * percu_index_out,
375
+ Dwarf_Sig8 * key_out,
376
+ Dwarf_Error *error)
377
+ {
378
+ Dwarf_Unsigned i = 0;
379
+ Dwarf_Unsigned m = 0;
380
+ int secnum_index = -1; /* L index */
381
+ int res = 0;
382
+
383
+ for ( i = 0; i< xuhdr->gx_column_count_sections; i++) {
384
+ /* We could put the secnums array into xuhdr
385
+ if looping here is too slow. */
386
+ const char *name = 0;
387
+ Dwarf_Unsigned num = 0;
388
+ res = dwarf_get_xu_section_names(xuhdr,i,&num,&name,error);
389
+ if (res != DW_DLV_OK) {
390
+ return res;
391
+ }
392
+ if (num == dfp_sect_num) {
393
+ secnum_index = i;
394
+ break;
395
+ }
396
+ }
397
+ if (secnum_index == -1) {
398
+ _dwarf_error(dbg,error,DW_DLE_FISSION_SECNUM_ERR);
399
+ return DW_DLV_ERROR;
400
+ }
401
+ for ( m = 0; m < xuhdr->gx_slots_in_hash; ++m) {
402
+ Dwarf_Sig8 hash;
403
+ Dwarf_Unsigned indexn = 0;
404
+ Dwarf_Unsigned sec_offset = 0;
405
+ Dwarf_Unsigned sec_size = 0;
406
+
407
+ res = dwarf_get_xu_hash_entry(xuhdr,m,&hash,&indexn,error);
408
+ if (res != DW_DLV_OK) {
409
+ return res;
410
+ }
411
+ if (indexn == 0 &&
412
+ !memcmp(&hash,&zerohashkey,sizeof(Dwarf_Sig8))) {
413
+ /* Empty slot. */
414
+ continue;
415
+ }
416
+
417
+ res = dwarf_get_xu_section_offset(xuhdr,
418
+ indexn,secnum_index,&sec_offset,&sec_size,error);
419
+ if (res != DW_DLV_OK) {
420
+ return res;
421
+ }
422
+ if (sec_offset != offset) {
423
+ continue;
424
+ }
425
+ *percu_index_out = indexn;
426
+ *key_out = hash;
427
+ return DW_DLV_OK;
428
+ }
429
+ return DW_DLV_NO_ENTRY;
430
+ }
431
+
432
+ static int
433
+ _dwarf_get_xuhdr(Dwarf_Debug dbg,
434
+ const char *sigtype,
435
+ Dwarf_Xu_Index_Header *xuout,
436
+ Dwarf_Error *error)
437
+ {
438
+ if (!strcmp(sigtype,"tu")) {
439
+ if (!dbg->de_tu_hashindex_data) {
440
+ return DW_DLV_NO_ENTRY;
441
+ }
442
+ *xuout = dbg->de_tu_hashindex_data;
443
+ } else if (!strcmp(sigtype,"cu")) {
444
+ if (!dbg->de_cu_hashindex_data) {
445
+ return DW_DLV_NO_ENTRY;
446
+ }
447
+ *xuout = dbg->de_cu_hashindex_data;
448
+ } else {
449
+ _dwarf_error(dbg,error,DW_DLE_SIG_TYPE_WRONG_STRING);
450
+ return DW_DLV_ERROR;
451
+ }
452
+ return DW_DLV_OK;
453
+
454
+ }
455
+
456
+ static int
457
+ transform_xu_to_dfp(Dwarf_Xu_Index_Header xuhdr,
458
+ Dwarf_Unsigned percu_index,
459
+ Dwarf_Sig8 *key,
460
+ const char *sig_type,
461
+ Dwarf_Debug_Fission_Per_CU * percu_out,
462
+ Dwarf_Error *error)
463
+ {
464
+ unsigned i = 0;
465
+ unsigned l = 0;
466
+ unsigned n = 1;
467
+ unsigned max_cols = xuhdr->gx_column_count_sections; /* L */
468
+ unsigned secnums[DW_FISSION_SECT_COUNT];
469
+ int res;
470
+ for ( i = 0; i< max_cols; i++) {
471
+ /* We could put the secnums array into xuhdr
472
+ if recreating it is too slow. */
473
+ const char *name = 0;
474
+ Dwarf_Unsigned num = 0;
475
+ res = dwarf_get_xu_section_names(xuhdr,i,&num,&name,error);
476
+ if (res != DW_DLV_OK) {
477
+ return res;
478
+ }
479
+ secnums[i] = num;
480
+ }
481
+ n = percu_index;
482
+ for(l = 0; l < max_cols; ++l) { /* L */
483
+ Dwarf_Unsigned sec_off = 0;
484
+ Dwarf_Unsigned sec_size = 0;
485
+ unsigned l_as_sect = secnums[l];
486
+ res = dwarf_get_xu_section_offset(xuhdr,n,l,
487
+ &sec_off,&sec_size,error);
488
+ if (res != DW_DLV_OK) {
489
+ return res;
490
+ }
491
+ percu_out->pcu_offset[l_as_sect] = sec_off;
492
+ percu_out->pcu_size[l_as_sect] = sec_size;
493
+ }
494
+ percu_out->pcu_type = sig_type;
495
+ percu_out->pcu_index = percu_index;
496
+ percu_out->pcu_hash = *key;
497
+ return DW_DLV_OK;
498
+ }
499
+
500
+ /* This should only be called for a CU, never a TU.
501
+ For a TU the type hash is known while reading
502
+ the TU Header. Not so for a CU. */
503
+ int
504
+ _dwarf_get_debugfission_for_offset(Dwarf_Debug dbg,
505
+ Dwarf_Off offset_wanted,
506
+ struct Dwarf_Debug_Fission_Per_CU_s * percu_out,
507
+ Dwarf_Error *error)
508
+ {
509
+ Dwarf_Xu_Index_Header xuhdr = 0;
510
+ int sres = 0;
511
+ Dwarf_Unsigned percu_index = 0;
512
+ Dwarf_Unsigned sect_index_base = 0;
513
+ const char * key_type = "cu";
514
+ Dwarf_Sig8 key;
515
+
516
+ sect_index_base = DW_SECT_INFO;
517
+
518
+ sres = _dwarf_get_xuhdr(dbg,key_type, &xuhdr,error);
519
+ if (sres != DW_DLV_OK) {
520
+ return sres;
521
+ }
522
+ sres = _dwarf_search_fission_for_offset(dbg,
523
+ xuhdr,offset_wanted, sect_index_base, &percu_index,
524
+ &key,
525
+ error);
526
+ if (sres != DW_DLV_OK) {
527
+ return sres;
528
+ }
529
+
530
+ sres = transform_xu_to_dfp(xuhdr,percu_index,&key,
531
+ key_type,percu_out, error);
532
+ return sres;
533
+
534
+ }
535
+ int
536
+ dwarf_get_debugfission_for_key(Dwarf_Debug dbg,
537
+ Dwarf_Sig8 * key /* pointer to hash signature */,
538
+ const char * key_type /* "cu" or "tu" */,
539
+ Dwarf_Debug_Fission_Per_CU * percu_out,
540
+ Dwarf_Error * error )
541
+ {
542
+ Dwarf_Xu_Index_Header xuhdr = 0;
543
+ int sres = 0;
544
+ Dwarf_Unsigned percu_index = 0;
545
+
546
+ sres = _dwarf_load_debug_info(dbg,error);
547
+ if (sres == DW_DLV_ERROR) {
548
+ return sres;
549
+ }
550
+ sres = _dwarf_load_debug_types(dbg,error);
551
+ if (sres == DW_DLV_ERROR) {
552
+ return sres;
553
+ }
554
+
555
+ sres = _dwarf_get_xuhdr(dbg,key_type, &xuhdr,error);
556
+ if (sres != DW_DLV_OK) {
557
+ return sres;
558
+ }
559
+
560
+ sres = _dwarf_search_fission_for_key(dbg,
561
+ xuhdr,key,&percu_index,error);
562
+ if (sres != DW_DLV_OK) {
563
+ return sres;
564
+ }
565
+
566
+ sres = transform_xu_to_dfp(xuhdr,percu_index,key,key_type,percu_out,error);
567
+ return sres;
568
+ }
569
+
570
+ void
571
+ dwarf_xu_header_free(Dwarf_Xu_Index_Header indexptr)
572
+ {
573
+ if(indexptr) {
574
+ Dwarf_Debug dbg = indexptr->gx_dbg;
575
+ dwarf_dealloc(dbg,indexptr,DW_DLA_XU_INDEX);
576
+ }
577
+ }
578
+
579
+