rdwarf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,120 @@
1
+ /*
2
+
3
+ Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved.
4
+
5
+ This program is free software; you can redistribute it and/or modify it
6
+ under the terms of version 2.1 of the GNU Lesser General Public License
7
+ as published by the Free Software Foundation.
8
+
9
+ This program is distributed in the hope that it would be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+
13
+ Further, this software is distributed without any warranty that it is
14
+ free of the rightful claim of any third person regarding infringement
15
+ or the like. Any license provided herein, whether implied or
16
+ otherwise, applies only to this software file. Patent licenses, if
17
+ any, provided herein do not apply to combinations of this program with
18
+ other software, or any other product whatsoever.
19
+
20
+ You should have received a copy of the GNU Lesser General Public
21
+ License along with this program; if not, write the Free Software
22
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
23
+ USA.
24
+
25
+ */
26
+
27
+
28
+
29
+ /*
30
+ Largest register value that can be coded into
31
+ the opcode since there are only 6 bits in the
32
+ register field.
33
+ */
34
+ #define MAX_6_BIT_VALUE 0x3f
35
+
36
+ /* This struct holds debug_frame instructions */
37
+ typedef struct Dwarf_P_Frame_Pgm_s *Dwarf_P_Frame_Pgm;
38
+
39
+ struct Dwarf_P_Frame_Pgm_s {
40
+ Dwarf_Ubyte dfp_opcode; /* opcode - includes reg # */
41
+ char *dfp_args; /* operands */
42
+ int dfp_nbytes; /* number of bytes in args */
43
+ #if 0
44
+ Dwarf_Unsigned dfp_sym_index; /* 0 unless reloc needed */
45
+ #endif
46
+ Dwarf_P_Frame_Pgm dfp_next;
47
+ };
48
+
49
+
50
+ /*
51
+ This struct has cie related information. Used to gather data
52
+ from user program, and later to transform to disk form
53
+ */
54
+ struct Dwarf_P_Cie_s {
55
+ Dwarf_Ubyte cie_version;
56
+ char *cie_aug; /* augmentation */
57
+ Dwarf_Ubyte cie_code_align; /* alignment of code */
58
+ Dwarf_Sbyte cie_data_align;
59
+ Dwarf_Ubyte cie_ret_reg; /* return register # */
60
+ char *cie_inst; /* initial instruction */
61
+ long cie_inst_bytes;
62
+ /* no of init_inst */
63
+ Dwarf_P_Cie cie_next;
64
+ };
65
+
66
+
67
+ /* producer fields */
68
+ struct Dwarf_P_Fde_s {
69
+ Dwarf_Unsigned fde_unused1;
70
+
71
+ /* function/subr die for this fde */
72
+ Dwarf_P_Die fde_die;
73
+
74
+ /* index to asso. cie */
75
+ Dwarf_Word fde_cie;
76
+
77
+ /* Address of first location of the code this frame applies to If
78
+ fde_end_symbol non-zero, this represents the offset from the
79
+ symbol indicated by fde_r_symidx */
80
+ Dwarf_Addr fde_initloc;
81
+
82
+ /* Relocation symbol for address of the code this frame applies to. */
83
+ Dwarf_Unsigned fde_r_symidx;
84
+
85
+ /* Bytes of instr for this fde, if known */
86
+ Dwarf_Unsigned fde_addr_range;
87
+
88
+ /* linked list of instructions we will put in fde. */
89
+ Dwarf_P_Frame_Pgm fde_inst;
90
+
91
+ /* number of instructions in fde */
92
+ long fde_n_inst;
93
+
94
+ /* number of bytes of inst in fde */
95
+ long fde_n_bytes;
96
+
97
+ /* offset into exception table for this function. */
98
+ Dwarf_Signed fde_offset_into_exception_tables;
99
+
100
+ /* The symbol for the exception table elf section. */
101
+ Dwarf_Unsigned fde_exception_table_symbol;
102
+
103
+ /* pointer to last inst */
104
+ Dwarf_P_Frame_Pgm fde_last_inst;
105
+
106
+ Dwarf_P_Fde fde_next;
107
+
108
+ /* The symbol and offset of the end symbol. When fde_end_symbol is
109
+ non-zero we must represent the */
110
+ Dwarf_Addr fde_end_symbol_offset;
111
+ Dwarf_Unsigned fde_end_symbol;
112
+
113
+ int fde_uwordb_size;
114
+ Dwarf_P_Debug fde_dbg;
115
+
116
+ /* If fde_block is non-null, then it is the set of instructions.
117
+ so we should use it rather than fde_inst. */
118
+ Dwarf_Unsigned fde_inst_block_size;
119
+ void *fde_block;
120
+ };
@@ -0,0 +1,50 @@
1
+ /*
2
+
3
+ Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright 2011 David Anderson. All Rights Reserved.
5
+
6
+ This program is free software; you can redistribute it and/or modify it
7
+ under the terms of version 2.1 of the GNU Lesser General Public License
8
+ as published by the Free Software Foundation.
9
+
10
+ This program is distributed in the hope that it would be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+
14
+ Further, this software is distributed without any warranty that it is
15
+ free of the rightful claim of any third person regarding infringement
16
+ or the like. Any license provided herein, whether implied or
17
+ otherwise, applies only to this software file. Patent licenses, if
18
+ any, provided herein do not apply to combinations of this program with
19
+ other software, or any other product whatsoever.
20
+
21
+ You should have received a copy of the GNU Lesser General Public
22
+ License along with this program; if not, write the Free Software
23
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24
+ USA.
25
+
26
+ */
27
+
28
+ #include "config.h"
29
+ #include "libdwarfdefs.h"
30
+ #include <stdio.h>
31
+ #include <string.h>
32
+ #ifdef HAVE_ELFACCESS_H
33
+ #include <elfaccess.h>
34
+ #endif
35
+ #include "pro_incl.h"
36
+ #include "pro_section.h"
37
+
38
+ /* This function adds another function name to the
39
+ list of function names for the given Dwarf_P_Debug.
40
+ It returns 0 on error, and 1 otherwise. */
41
+ Dwarf_Unsigned
42
+ dwarf_add_funcname(Dwarf_P_Debug dbg,
43
+ Dwarf_P_Die die,
44
+ char *function_name, Dwarf_Error * error)
45
+ {
46
+ return
47
+ _dwarf_add_simple_name_entry(dbg, die, function_name,
48
+ dwarf_snk_funcname, error);
49
+
50
+ }
@@ -0,0 +1,91 @@
1
+ /*
2
+
3
+ Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
5
+ Portions Copyright 2008-2012 David Anderson. All rights reserved.
6
+ Portions Copyright 2010-2012 SN Systems Ltd. All rights reserved.
7
+
8
+ This program is free software; you can redistribute it and/or modify it
9
+ under the terms of version 2.1 of the GNU Lesser General Public License
10
+ as published by the Free Software Foundation.
11
+
12
+ This program is distributed in the hope that it would be useful, but
13
+ WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+
16
+ Further, this software is distributed without any warranty that it is
17
+ free of the rightful claim of any third person regarding infringement
18
+ or the like. Any license provided herein, whether implied or
19
+ otherwise, applies only to this software file. Patent licenses, if
20
+ any, provided herein do not apply to combinations of this program with
21
+ other software, or any other product whatsoever.
22
+
23
+ You should have received a copy of the GNU Lesser General Public
24
+ License along with this program; if not, write the Free Software
25
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
26
+ USA.
27
+
28
+ */
29
+
30
+ /* Windows specific */
31
+ #ifdef HAVE_STDAFX_H
32
+ #include "stdafx.h"
33
+ #endif /* HAVE_STDAFX_H */
34
+
35
+ #ifdef HAVE_ELF_H
36
+ #include <elf.h>
37
+ #elif defined(HAVE_LIBELF_H)
38
+ /* On one platform without elf.h this gets Elf32_Rel
39
+ type defined (a required type). */
40
+ #include <libelf.h>
41
+ /* Consider the other known directory too */
42
+ #elif defined(HAVE_LIBELF_LIBELF_H)
43
+ #include <libelf/libelf.h>
44
+ #endif
45
+
46
+ #if defined(sun)
47
+ #include <sys/elf_SPARC.h>
48
+ #include <sys/elf_386.h>
49
+ #endif
50
+
51
+ /* The target address is given: the place in the source integer
52
+ is to be determined.
53
+ */
54
+ #ifdef WORDS_BIGENDIAN
55
+ #define WRITE_UNALIGNED(dbg,dest,source, srclength,len_out) \
56
+ { \
57
+ dbg->de_copy_word(dest, \
58
+ ((const char *)source) +(srclength)-(len_out),\
59
+ (len_out)) ; \
60
+ }
61
+
62
+
63
+ #else /* LITTLE ENDIAN */
64
+
65
+ #define WRITE_UNALIGNED(dbg,dest,source, srclength,len_out) \
66
+ { \
67
+ dbg->de_copy_word( (dest) , \
68
+ ((const char *)source) , \
69
+ (len_out)) ; \
70
+ }
71
+ #endif
72
+
73
+
74
+ #if defined(sparc) && defined(sun)
75
+ #define REL32 Elf32_Rela
76
+ #define REL64 Elf64_Rela
77
+ #define REL_SEC_PREFIX ".rela"
78
+ #else
79
+ #define REL32 Elf32_Rel
80
+ #define REL64 Elf64_Rel
81
+ #define REL_SEC_PREFIX ".rel"
82
+ #endif
83
+
84
+ #include "dwarf.h"
85
+ #include "libdwarf.h"
86
+
87
+ #include "pro_opaque.h"
88
+ #include "pro_error.h"
89
+ #include "pro_util.h"
90
+ #include "pro_encode_nm.h"
91
+ #include "pro_alloc.h"
@@ -0,0 +1,327 @@
1
+ /*
2
+
3
+ Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved.
4
+ Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
5
+ Portions Copyright 2008-2014 David Anderson, Inc. All rights reserved.
6
+ Portions Copyright 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 "libdwarfdefs.h"
32
+ #include <stdio.h>
33
+ #include <string.h>
34
+ #include "pro_incl.h"
35
+ #include "pro_line.h"
36
+ #include "pro_section.h" /* for MAGIC_SECT_NO */
37
+ #include "pro_reloc_symbolic.h"
38
+ #include "pro_reloc_stream.h"
39
+
40
+ #define IS_64BITPTR(dbg) ((dbg)->de_flags & DW_DLC_POINTER64 ? 1 : 0)
41
+ #define ISA_IA64(dbg) ((dbg)->de_flags & DW_DLC_ISA_IA64 ? 1 : 0)
42
+
43
+ struct isa_relocs_s {
44
+ const char *name_;
45
+ int reloc32_;
46
+ int reloc64_;
47
+ int segrel_; /* only used if IRIX */
48
+ };
49
+
50
+ /* Some of these may be the wrong relocation for DWARF
51
+ relocations. FIXME. Most will be unusable without
52
+ additional effort as they have not been tested.
53
+ */
54
+ #define R_MIPS_32 2
55
+ #define R_MIPS_64 18
56
+ #define R_MIPS_SCN_DISP 32
57
+ #define R_386_32 1
58
+ #define R_386_64 0 /* impossible */
59
+ #define R_X86_64_32 10
60
+ #define R_X86_64_64 1
61
+ #define R_SPARC_UA32 23
62
+ #define R_SPARC_UA64 54
63
+ #define R_ARM_ABS32 2
64
+ #define R_ARM_ABS64 0 /* impossible */
65
+ #define R_AARCH64_ABS32 258
66
+ #define R_AARCH64_ABS64 257
67
+ #define R_IA64_DIR32LSB 0x25
68
+ #define R_IA64_DIR64LSB 0x27
69
+ #define R_PPC_REL32 26
70
+ #define R_PPC_REL64 44
71
+ #define R_PPC64_REL32 R_PPC_REL32
72
+ #define R_PPC64_REL64 44
73
+
74
+
75
+ static struct isa_relocs_s isa_relocs[] = {
76
+ {"irix", R_MIPS_32,R_MIPS_64,R_MIPS_SCN_DISP},
77
+ {"mips", R_MIPS_32,R_MIPS_64,0},
78
+ {"x86", R_386_32, R_386_64,0},
79
+ {"x86_64",R_X86_64_32,R_X86_64_64,0},
80
+ {"ia64", R_IA64_DIR32LSB,R_IA64_DIR64LSB,0},
81
+ {"arm64", R_AARCH64_ABS32,R_AARCH64_ABS64,0},
82
+ {"arm", R_ARM_ABS32,R_ARM_ABS64,0},
83
+ {"ppc", R_PPC_REL32,R_PPC_REL64,0},
84
+ {"ppc64", R_PPC64_REL32,R_PPC64_REL64,0},
85
+ {"sparc", R_SPARC_UA32,R_SPARC_UA64,0},
86
+ /* The last entry MUST be all zeros. */
87
+ {0,0,0,0}
88
+ };
89
+
90
+
91
+ static int common_init(Dwarf_P_Debug dbg, Dwarf_Unsigned flags,
92
+ const char *abiname, const char *dwarf_version,
93
+ int *error_ret);
94
+
95
+ void *_dwarf_memcpy_swap_bytes(void *s1, const void *s2, size_t len);
96
+
97
+ /* This function sets up a new dwarf producing region.
98
+ flags: Indicates type of access method, one of DW_DLC* macros
99
+ func(): Used to create a new object file, a call back function
100
+ errhand(): Error Handler provided by user
101
+ errarg: Argument to errhand()
102
+ error: returned error value */
103
+ /* We want the following to have an elf section number that matches
104
+ 'nothing' */
105
+ static struct Dwarf_P_Section_Data_s init_sect = {
106
+ MAGIC_SECT_NO, 0, 0, 0, 0
107
+ };
108
+
109
+ /* New April 2014.
110
+ Replaces all previous producer init functions.
111
+ It adds a string to select the relevant ABI/ISA and
112
+ a string defining the selected DWARF version to
113
+ output.
114
+ There are some overlaps between the flags and the ISA/ABI
115
+ string choices. ( it is neither strictly ABI nor strictly
116
+ ISA name, but a useful name for both.)
117
+ Generally, the function inteprets these
118
+ in a tolerant fashion, so inconsistencies in the
119
+ selections are not noticed...but they may have a surprising
120
+ effect.
121
+
122
+ The extra string is a way to allow new options without
123
+ changing the interface. The idea is the caller might
124
+ supply a list of such things as one string, comma-separated.
125
+ The interface is not intended to allow spaces or tabs in the
126
+ names, so don't do that :-)
127
+ If no extra strings are needed (none are defined initially)
128
+ then pass a NULL pointer or an empty string as the 'extra'
129
+ parameter.
130
+ */
131
+ int
132
+ dwarf_producer_init(Dwarf_Unsigned flags,
133
+ Dwarf_Callback_Func func,
134
+ Dwarf_Handler errhand,
135
+ Dwarf_Ptr errarg,
136
+ void * user_data,
137
+ const char *isa_name, /* See isa_reloc_s. */
138
+ const char *dwarf_version, /* V2 V3 V4 or V5. */
139
+ const char *extra, /* Extra input strings, comma separated. */
140
+ Dwarf_P_Debug *dbg_returned,
141
+ Dwarf_Error * error)
142
+ {
143
+ Dwarf_P_Debug dbg = 0;
144
+ int res = 0;
145
+ int err_ret = 0;
146
+ dbg = (Dwarf_P_Debug) _dwarf_p_get_alloc(NULL,
147
+ sizeof(struct Dwarf_P_Debug_s));
148
+ if (dbg == NULL) {
149
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_DBG_ALLOC,
150
+ DW_DLV_ERROR);
151
+ }
152
+ memset((void *) dbg, 0, sizeof(struct Dwarf_P_Debug_s));
153
+ /* For the time being */
154
+ if (func == NULL) {
155
+ DWARF_P_DBG_ERROR(dbg, DW_DLE_NO_CALLBACK_FUNC,
156
+ DW_DLV_ERROR);
157
+ }
158
+ dbg->de_callback_func = func;
159
+ dbg->de_errhand = errhand;
160
+ dbg->de_errarg = errarg;
161
+ dbg->de_user_data = user_data;
162
+ res = common_init(dbg, flags,isa_name,dwarf_version,&err_ret);
163
+ if (res != DW_DLV_OK) {
164
+ DWARF_P_DBG_ERROR(dbg, err_ret,
165
+ DW_DLV_ERROR);
166
+ }
167
+ *dbg_returned = dbg;
168
+ return DW_DLV_OK;
169
+ }
170
+
171
+ static int
172
+ set_reloc_numbers(Dwarf_P_Debug dbg,Dwarf_Unsigned flags,const char *abiname)
173
+ {
174
+ struct isa_relocs_s *isap = 0;
175
+ for(isap = &isa_relocs[0]; ;isap++) {
176
+ if (!isap->name_) {
177
+ /* No more names known. Never found the one we wanted. */
178
+ return DW_DLV_NO_ENTRY;
179
+ }
180
+ if (!strcmp(abiname,isap->name_)) {
181
+ if (dbg->de_pointer_size == 4) {
182
+ dbg->de_ptr_reloc = isap->reloc32_;
183
+ } else {
184
+ dbg->de_ptr_reloc = isap->reloc64_;
185
+ }
186
+ if (dbg->de_offset_size == 4) {
187
+ dbg->de_offset_reloc = isap->reloc32_;
188
+ } else {
189
+ dbg->de_offset_reloc = isap->reloc64_;
190
+ }
191
+ /* segrel only meaningful for IRIX, otherwise
192
+ harmless, unused. */
193
+ dbg->de_exc_reloc = isap->segrel_;
194
+ return DW_DLV_OK;
195
+ }
196
+ }
197
+ /* UNREACHED */
198
+ };
199
+
200
+ static int
201
+ common_init(Dwarf_P_Debug dbg, Dwarf_Unsigned flags, const char *abiname,
202
+ const char *dwarf_version,
203
+ int *err_ret)
204
+ {
205
+ unsigned int k = 0;
206
+ int res = 0;
207
+
208
+ dbg->de_version_magic_number = PRO_VERSION_MAGIC;
209
+ dbg->de_n_debug_sect = 0;
210
+ dbg->de_debug_sects = &init_sect;
211
+ dbg->de_current_active_section = &init_sect;
212
+ dbg->de_flags = flags;
213
+ _dwarf_init_default_line_header_vals(dbg);
214
+
215
+
216
+ if(dbg->de_flags & DW_DLC_POINTER64) {
217
+ dbg->de_pointer_size = 8;
218
+ } else {
219
+ /* DW_DLC_POINTER32 assumed. */
220
+ dbg->de_pointer_size = 4;
221
+ }
222
+ if(dbg->de_flags & DW_DLC_OFFSET64) {
223
+ dbg->de_offset_size = 8;
224
+ dbg->de_64bit_extension = 0;
225
+ } else {
226
+ if(dbg->de_flags & DW_DLC_IRIX_OFFSET64) {
227
+ dbg->de_offset_size = 8;
228
+ dbg->de_64bit_extension = 1;
229
+ } else {
230
+ /* offset size 4 assumed. */
231
+ dbg->de_offset_size = 4;
232
+ dbg->de_64bit_extension = 0;
233
+ }
234
+ }
235
+ if(abiname && (!strcmp(abiname,"irix"))) {
236
+ dbg->de_irix_exc_augmentation = 1;
237
+ } else {
238
+ dbg->de_irix_exc_augmentation = 0;
239
+ }
240
+ /* We must set reloc numbers even if doing symbolic
241
+ relocations because we use the numbers up until
242
+ we are generating debug. A zero is interpreted
243
+ as no relocations. So ensure we have real
244
+ relocations. */
245
+ res = set_reloc_numbers(dbg,flags,abiname);
246
+ if (res != DW_DLV_OK) {
247
+ *err_ret = DW_DLE_BAD_ABINAME;
248
+ return DW_DLV_ERROR;
249
+ }
250
+ if(!dwarf_version) {
251
+ dbg->de_output_version = 2;
252
+ } else if (!strcmp(dwarf_version,"V2")) {
253
+ dbg->de_output_version = 2;
254
+ } else if (!strcmp(dwarf_version,"V3")) {
255
+ dbg->de_output_version = 3;
256
+ } else if (!strcmp(dwarf_version,"V4")) {
257
+ dbg->de_output_version = 4;
258
+ } else if (!strcmp(dwarf_version,"V5")) {
259
+ dbg->de_output_version = 5;
260
+ } else {
261
+ /* The default. */
262
+ dbg->de_output_version = 2;
263
+ }
264
+
265
+ if (flags & DW_DLC_SYMBOLIC_RELOCATIONS) {
266
+ dbg->de_relocation_record_size =
267
+ sizeof(struct Dwarf_Relocation_Data_s);
268
+ } else {
269
+ /* This is only going to work when the HOST == TARGET,
270
+ surely? */
271
+ #if HAVE_ELF64_GETEHDR
272
+ dbg->de_relocation_record_size =
273
+ ((dbg->de_pointer_size == 8)? sizeof(REL64) : sizeof(REL32));
274
+ #else
275
+ dbg->de_relocation_record_size = sizeof(REL32);
276
+ #endif
277
+
278
+ }
279
+
280
+ /* FIXME: conditional on the DWARF version target,
281
+ dbg->de_output_version. */
282
+ if (dbg->de_offset_size == 8) {
283
+ dbg->de_ar_data_attribute_form = DW_FORM_data8;
284
+ dbg->de_ar_ref_attr_form = DW_FORM_ref8;
285
+ } else {
286
+ dbg->de_ar_data_attribute_form = DW_FORM_data4;
287
+ dbg->de_ar_ref_attr_form = DW_FORM_ref4;
288
+ }
289
+
290
+ if (flags & DW_DLC_SYMBOLIC_RELOCATIONS) {
291
+ dbg->de_reloc_name = _dwarf_pro_reloc_name_symbolic;
292
+ dbg->de_reloc_pair = _dwarf_pro_reloc_length_symbolic;
293
+ dbg->de_transform_relocs_to_disk =
294
+ _dwarf_symbolic_relocs_to_disk;
295
+ } else {
296
+ if (IS_64BITPTR(dbg)) {
297
+ dbg->de_reloc_name = _dwarf_pro_reloc_name_stream64;
298
+ } else {
299
+ dbg->de_reloc_name = _dwarf_pro_reloc_name_stream32;
300
+ }
301
+ dbg->de_reloc_pair = 0;
302
+ dbg->de_transform_relocs_to_disk = _dwarf_stream_relocs_to_disk;
303
+ }
304
+ for (k = 0; k < NUM_DEBUG_SECTIONS; ++k) {
305
+
306
+ Dwarf_P_Per_Reloc_Sect prel = &dbg->de_reloc_sect[k];
307
+
308
+ prel->pr_slots_per_block_to_alloc = DEFAULT_SLOTS_PER_BLOCK;
309
+ }
310
+ /* First assume host, target same endianness */
311
+ dbg->de_same_endian = 1;
312
+ dbg->de_copy_word = memcpy;
313
+ #ifdef WORDS_BIGENDIAN
314
+ /* host is big endian, so what endian is target? */
315
+ if (flags & DW_DLC_TARGET_LITTLEENDIAN) {
316
+ dbg->de_same_endian = 0;
317
+ dbg->de_copy_word = _dwarf_memcpy_swap_bytes;
318
+ }
319
+ #else /* little endian */
320
+ /* host is little endian, so what endian is target? */
321
+ if (flags & DW_DLC_TARGET_BIGENDIAN) {
322
+ dbg->de_same_endian = 0;
323
+ dbg->de_copy_word = _dwarf_memcpy_swap_bytes;
324
+ }
325
+ #endif /* !WORDS_BIGENDIAN */
326
+ return DW_DLV_OK;
327
+ }