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,81 @@
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
+ /* libdwarfdefs.h
28
+ */
29
+
30
+ #ifndef LIBDWARFDEFS_H
31
+ #define LIBDWARFDEFS_H
32
+
33
+ /* We want __uint32_t and __uint64_t and __int32_t __int64_t
34
+ properly defined but not duplicated, since duplicate typedefs
35
+ are not legal C.
36
+ */
37
+ /*
38
+ HAVE___UINT32_T
39
+ HAVE___UINT64_T will be set by configure if
40
+ our 4 types are predefined in compiler
41
+ */
42
+
43
+
44
+ #if (!defined(HAVE___UINT32_T)) && defined(HAVE___UINT32_T_IN_SGIDEFS_H)
45
+ #include <sgidefs.h> /* sgidefs.h defines them */
46
+ #define HAVE___UINT32_T 1
47
+ #endif
48
+
49
+ #if (!defined(HAVE___UINT64_T)) && defined(HAVE___UINT64_T_IN_SGIDEFS_H)
50
+ #include <sgidefs.h> /* sgidefs.h defines them */
51
+ #define HAVE___UINT64_T 1
52
+ #endif
53
+
54
+
55
+ #if (!defined(HAVE___UINT32_T)) && \
56
+ defined(HAVE_SYS_TYPES_H) && \
57
+ defined(HAVE___UINT32_T_IN_SYS_TYPES_H)
58
+ # include <sys/types.h>
59
+ #define HAVE___UINT32_T 1
60
+ #endif
61
+
62
+ #if (!defined(HAVE___UINT64_T)) && \
63
+ defined(HAVE_SYS_TYPES_H) && \
64
+ defined(HAVE___UINT64_T_IN_SYS_TYPES_H)
65
+ # include <sys/types.h>
66
+ #define HAVE___UINT64_T 1
67
+ #endif
68
+
69
+ #ifndef HAVE___UINT32_T
70
+ typedef int __int32_t;
71
+ typedef unsigned __uint32_t;
72
+ #define HAVE___UINT32_T 1
73
+ #endif
74
+
75
+ #ifndef HAVE___UINT64_T
76
+ typedef long long __int64_t;
77
+ typedef unsigned long long __uint64_t;
78
+ #define HAVE___UINT64_T 1
79
+ #endif
80
+
81
+ #endif /* LIBDWARFDEFS_H */
@@ -0,0 +1,327 @@
1
+ /*
2
+
3
+ Copyright (C) 2005 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
+ /* malloc_check.c For checking dealloc completeness.
28
+
29
+ This code is as simple as possible and works ok for
30
+ reasonable size allocation counts.
31
+
32
+ It treats allocation as global, and so will not
33
+ work very well if an application opens more than one
34
+ Dwarf_Debug.
35
+
36
+ */
37
+
38
+ #include <stdio.h>
39
+ #include <stdlib.h> /* for exit() and various malloc
40
+ prototypes */
41
+ #include "config.h"
42
+ #include "dwarf_incl.h"
43
+ #include "malloc_check.h"
44
+ #ifdef WANT_LIBBDWARF_MALLOC_CHECK
45
+
46
+ /* To turn off printing every entry, just change the define
47
+ to set PRINT_MALLOC_DETAILS 0.
48
+ */
49
+ #define PRINT_MALLOC_DETAILS 0
50
+
51
+ #define MC_TYPE_UNKNOWN 0
52
+ #define MC_TYPE_ALLOC 1
53
+ #define MC_TYPE_DEALLOC 2
54
+
55
+ struct mc_data_s {
56
+ struct mc_data_s *mc_prev;
57
+ unsigned long mc_address; /* Assumes this is large enough to hold
58
+ a pointer! */
59
+
60
+ long mc_alloc_number; /* Assigned in order by when record
61
+ created. */
62
+ unsigned char mc_alloc_code; /* Allocation code, libdwarf. */
63
+ unsigned char mc_type;
64
+ unsigned char mc_dealloc_noted; /* Used on an ALLOC node. */
65
+ unsigned char mc_dealloc_noted_count; /* Used on an ALLOC
66
+ node. */
67
+ };
68
+
69
+ /*
70
+
71
+ */
72
+ #define HASH_TABLE_SIZE 10501
73
+ static struct mc_data_s *mc_data_hash[HASH_TABLE_SIZE];
74
+ static long mc_data_list_size = 0;
75
+
76
+ static char *alloc_type_name[MAX_DW_DLA + 1] = {
77
+ "",
78
+ "DW_DLA_STRING",
79
+ "DW_DLA_LOC",
80
+ "DW_DLA_LOCDESC",
81
+ "DW_DLA_ELLIST",
82
+ "DW_DLA_BOUNDS",
83
+ "DW_DLA_BLOCK",
84
+ "DW_DLA_DEBUG",
85
+ "DW_DLA_DIE",
86
+ "DW_DLA_LINE",
87
+ "DW_DLA_ATTR",
88
+ "DW_DLA_TYPE",
89
+ "DW_DLA_SUBSCR",
90
+ "DW_DLA_GLOBAL",
91
+ "DW_DLA_ERROR",
92
+ "DW_DLA_LIST",
93
+ "DW_DLA_LINEBUF",
94
+ "DW_DLA_ARANGE",
95
+ "DW_DLA_ABBREV",
96
+ "DW_DLA_FRAME_OP",
97
+ "DW_DLA_CIE",
98
+ "DW_DLA_FDE",
99
+ "DW_DLA_LOC_BLOCK",
100
+ "DW_DLA_FRAME_BLOCK",
101
+ "DW_DLA_FUNC",
102
+ "DW_DLA_TYPENAME",
103
+ "DW_DLA_VAR",
104
+ "DW_DLA_WEAK",
105
+ "DW_DLA_ADDR",
106
+ "DW_DLA_ABBREV_LIST",
107
+ "DW_DLA_CHAIN",
108
+ "DW_DLA_CU_CONTEXT",
109
+ "DW_DLA_FRAME",
110
+ "DW_DLA_GLOBAL_CONTEXT",
111
+ "DW_DLA_FILE_ENTRY",
112
+ "DW_DLA_LINE_CONTEXT",
113
+ "DW_DLA_LOC_CHAIN",
114
+ "DW_DLA_HASH_TABLE",
115
+ "DW_DLA_FUNC_CONTEXT",
116
+ "DW_DLA_TYPENAME_CONTEXT",
117
+ "DW_DLA_VAR_CONTEXT",
118
+ "DW_DLA_WEAK_CONTEXT",
119
+ "DW_DLA_PUBTYPES_CONTEXT"
120
+ /* Don't forget to expand this list if the list of codes
121
+ expands. */
122
+ };
123
+
124
+ static unsigned
125
+ hash_address(unsigned long addr)
126
+ {
127
+ unsigned long a = addr >> 2;
128
+
129
+ return a % HASH_TABLE_SIZE;
130
+ }
131
+
132
+ #if PRINT_MALLOC_DETAILS
133
+ static void
134
+ print_alloc_dealloc_detail(unsigned long addr,
135
+ int code, char *whichisit)
136
+ {
137
+ fprintf(stderr,
138
+ "%s addr 0x%lx code %d (%s) entry %ld\n",
139
+ whichisit, addr, code, alloc_type_name[code],
140
+ mc_data_list_size);
141
+ }
142
+ #else
143
+ #define print_alloc_dealloc_detail(a,b,c) /* nothing */
144
+ #endif
145
+
146
+ /* Create a zeroed struct or die. */
147
+ static void *
148
+ newone(void)
149
+ {
150
+ struct mc_data_s *newd = malloc(sizeof(struct mc_data_s));
151
+
152
+ if (newd == 0) {
153
+ fprintf(stderr, "out of memory , # %ld\n", mc_data_list_size);
154
+ exit(1);
155
+ }
156
+ memset(newd, 0, sizeof(struct mc_data_s));
157
+ return newd;
158
+ }
159
+
160
+ /* Notify checker that get_alloc has allocated user data. */
161
+ void
162
+ dwarf_malloc_check_alloc_data(void *addr_in, unsigned char code)
163
+ {
164
+ struct mc_data_s *newd = newone();
165
+ unsigned long addr = (unsigned long) addr_in;
166
+ struct mc_data_s **base = &mc_data_hash[hash_address(addr)];
167
+
168
+ print_alloc_dealloc_detail(addr, code, "alloc ");
169
+ newd->mc_address = addr;
170
+ newd->mc_alloc_code = code;
171
+ newd->mc_type = MC_TYPE_ALLOC;
172
+ newd->mc_alloc_number = mc_data_list_size;
173
+ newd->mc_prev = *base;
174
+ *base = newd;
175
+ newd->mc_alloc_number = mc_data_list_size;
176
+ mc_data_list_size += 1;
177
+ }
178
+
179
+ static void
180
+ print_entry(char *msg, struct mc_data_s *data)
181
+ {
182
+ fprintf(stderr,
183
+ "%s: 0x%08lx code %2d (%s) type %s dealloc noted %u ct %u\n",
184
+ msg,
185
+ (long) data->mc_address,
186
+ data->mc_alloc_code,
187
+ alloc_type_name[data->mc_alloc_code],
188
+ (data->mc_type == MC_TYPE_ALLOC) ? "alloc " :
189
+ (data->mc_type == MC_TYPE_DEALLOC) ? "dealloc" : "unknown",
190
+ (unsigned) data->mc_dealloc_noted,
191
+ (unsigned) data->mc_dealloc_noted_count);
192
+ }
193
+
194
+ /* newd is a 'dealloc'.
195
+ */
196
+ static long
197
+ balanced_by_alloc_p(struct mc_data_s *newd,
198
+ long *addr_match_num,
199
+ struct mc_data_s **addr_match,
200
+ struct mc_data_s *base)
201
+ {
202
+ struct mc_data_s *cur = base;
203
+
204
+ for (; cur; cur = cur->mc_prev) {
205
+ if (cur->mc_address == newd->mc_address) {
206
+ if (cur->mc_type == MC_TYPE_ALLOC) {
207
+ if (cur->mc_alloc_code == newd->mc_alloc_code) {
208
+ *addr_match = cur;
209
+ *addr_match_num = cur->mc_alloc_number;
210
+ return cur->mc_alloc_number;
211
+ } else {
212
+ /* code mismatch */
213
+ *addr_match = cur;
214
+ *addr_match_num = cur->mc_alloc_number;
215
+ return -1;
216
+ }
217
+ } else {
218
+ /* Unbalanced new/del */
219
+ *addr_match = cur;
220
+ *addr_match_num = cur->mc_alloc_number;
221
+ return -1;
222
+ }
223
+ }
224
+ }
225
+ return -1;
226
+ }
227
+
228
+ /* A dealloc is to take place. Ensure it balances an alloc.
229
+ */
230
+ void
231
+ dwarf_malloc_check_dealloc_data(void *addr_in, unsigned char code)
232
+ {
233
+ struct mc_data_s *newd = newone();
234
+ long prev;
235
+ long addr_match_num = -1;
236
+ struct mc_data_s *addr_match = 0;
237
+ unsigned long addr = (unsigned long) addr_in;
238
+ struct mc_data_s **base = &mc_data_hash[hash_address(addr)];
239
+
240
+
241
+ print_alloc_dealloc_detail(addr, code, "dealloc ");
242
+ newd->mc_address = (unsigned long) addr;
243
+ newd->mc_alloc_code = code;
244
+ newd->mc_type = MC_TYPE_DEALLOC;
245
+ newd->mc_prev = *base;
246
+ prev =
247
+ balanced_by_alloc_p(newd, &addr_match_num, &addr_match, *base);
248
+ if (prev < 0) {
249
+ fprintf(stderr,
250
+ "Unbalanced dealloc at index %ld\n", mc_data_list_size);
251
+ print_entry("new", newd);
252
+ fprintf(stderr, "addr-match_num? %ld\n", addr_match_num);
253
+ if (addr_match) {
254
+ print_entry("prev entry", addr_match);
255
+ if (addr_match->mc_dealloc_noted > 1) {
256
+ fprintf(stderr, "Above is Duplicate dealloc!\n");
257
+ }
258
+ }
259
+ abort();
260
+ exit(3);
261
+ }
262
+ addr_match->mc_dealloc_noted = 1;
263
+ addr_match->mc_dealloc_noted_count += 1;
264
+ if (addr_match->mc_dealloc_noted_count > 1) {
265
+ fprintf(stderr, "Double dealloc entry %ld\n", addr_match_num);
266
+ print_entry("new dealloc entry", newd);
267
+ print_entry("bad alloc entry", addr_match);
268
+ }
269
+ *base = newd;
270
+ mc_data_list_size += 1;
271
+ }
272
+
273
+ /* Final check for leaks.
274
+ */
275
+ void
276
+ dwarf_malloc_check_complete(char *msg)
277
+ {
278
+ long i = 0;
279
+ long total = mc_data_list_size;
280
+ long hash_slots_used = 0;
281
+ long max_chain_length = 0;
282
+
283
+ fprintf(stderr, "Run complete, %s. %ld entries\n", msg, total);
284
+ for (; i < HASH_TABLE_SIZE; ++i) {
285
+ struct mc_data_s *cur = mc_data_hash[i];
286
+ long cur_chain_length = 0;
287
+
288
+ if (cur == 0)
289
+ continue;
290
+ ++hash_slots_used;
291
+ for (; cur; cur = cur->mc_prev) {
292
+ ++cur_chain_length;
293
+ if (cur->mc_type == MC_TYPE_ALLOC) {
294
+ if (cur->mc_dealloc_noted) {
295
+ if (cur->mc_dealloc_noted > 1) {
296
+ fprintf(stderr,
297
+ " Duplicate dealloc! entry %ld\n",
298
+ cur->mc_alloc_number);
299
+ print_entry("duplicate dealloc", cur);
300
+
301
+ }
302
+ continue;
303
+ } else {
304
+ fprintf(stderr, "malloc no dealloc, entry %ld\n",
305
+ cur->mc_alloc_number);
306
+ print_entry("dangle", cur);
307
+ }
308
+ } else {
309
+ /* mc_type is MC_TYPE_DEALLOC, already checked */
310
+
311
+ }
312
+ }
313
+ if (cur_chain_length > max_chain_length) {
314
+ max_chain_length = cur_chain_length;
315
+ }
316
+ }
317
+ fprintf(stderr, "mc hash table slots=%ld, "
318
+ "used=%ld, maxchain=%ld\n",
319
+ (long) HASH_TABLE_SIZE, hash_slots_used, max_chain_length);
320
+ return;
321
+ }
322
+
323
+ #else
324
+
325
+ extern void *libdwarf_an_unused_function_so_not_empty_c_file(void);
326
+
327
+ #endif /* WANT_LIBBDWARF_MALLOC_CHECK */
@@ -0,0 +1,52 @@
1
+ /*
2
+
3
+ Copyright (C) 2005 Silicon Graphics, Inc. All Rights Reserved.
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
+ /* malloc_check.h */
27
+
28
+ /* A simple libdwarf-aware malloc checker.
29
+ define WANT_LIBBDWARF_MALLOC_CHECK and rebuild libdwarf
30
+ do make a checking-for-alloc-mistakes libdwarf.
31
+ NOT recommended for production use.
32
+
33
+ When defined, also add malloc_check.c to the list of
34
+ files in Makefile.
35
+ */
36
+
37
+ #undef WANT_LIBBDWARF_MALLOC_CHECK
38
+ /*#define WANT_LIBBDWARF_MALLOC_CHECK 1 */
39
+
40
+ #ifdef WANT_LIBBDWARF_MALLOC_CHECK
41
+
42
+ void dwarf_malloc_check_alloc_data(void * addr,unsigned char code);
43
+ void dwarf_malloc_check_dealloc_data(void * addr,unsigned char code);
44
+ void dwarf_malloc_check_complete(char *wheremsg); /* called at exit of app */
45
+
46
+ #else /* !WANT_LIBBDWARF_MALLOC_CHECK */
47
+
48
+ #define dwarf_malloc_check_alloc_data(a,b) /* nothing */
49
+ #define dwarf_malloc_check_dealloc_data(a,b) /* nothing */
50
+ #define dwarf_malloc_check_complete(a) /* nothing */
51
+
52
+ #endif /* WANT_LIBBDWARF_MALLOC_CHECK */