2 * sgen-grep-binprot.c: Platform specific binary protocol entries reader
4 * Copyright (C) 2016 Xamarin Inc
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
18 #include "sgen-entry-stream.h"
19 #include "sgen-grep-binprot.h"
21 static int file_version
= 0;
23 #ifdef BINPROT_HAS_HEADER
24 #define PACKED_SUFFIX p
26 #define PROTOCOL_STRUCT_ATTR
30 #ifndef BINPROT_SIZEOF_VOID_P
31 #define BINPROT_SIZEOF_VOID_P SIZEOF_VOID_P
35 #if BINPROT_SIZEOF_VOID_P == 4
36 typedef int32_t mword
;
37 #define MWORD_FORMAT_SPEC_D PRId32
38 #define MWORD_FORMAT_SPEC_P PRIx32
40 #define ARCH_SUFFIX 32
43 typedef int64_t mword
;
44 #define MWORD_FORMAT_SPEC_D PRId64
45 #define MWORD_FORMAT_SPEC_P PRIx64
47 #define ARCH_SUFFIX 64
50 #define TYPE_SIZE mword
51 #define TYPE_POINTER mword
52 #include <mono/sgen/sgen-protocol.h>
54 #define SGEN_PROTOCOL_EOF 255
56 #define TYPE(t) ((t) & 0x7f)
57 #define WORKER(t) ((t) & 0x80)
59 #define MAX_ENTRY_SIZE (1 << 10)
62 read_entry (EntryStream
*stream
, void *data
, unsigned char *windex
)
67 if (read_stream (stream
, &type
, 1) <= 0)
68 return SGEN_PROTOCOL_EOF
;
71 if (file_version
>= 2) {
72 if (read_stream (stream
, windex
, 1) <= 0)
73 return SGEN_PROTOCOL_EOF
;
75 *windex
= !!(WORKER (type
));
79 switch (TYPE (type
)) {
81 #define BEGIN_PROTOCOL_ENTRY0(method) \
82 case PROTOCOL_ID(method): size = 0; break;
83 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
84 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
85 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
86 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
87 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
88 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
89 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
90 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
91 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
92 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
93 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
94 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
96 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
97 BEGIN_PROTOCOL_ENTRY0 (method)
98 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
99 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
100 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
101 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
102 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
103 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
104 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
105 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
106 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
107 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
108 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
109 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
111 #define DEFAULT_PRINT()
112 #define CUSTOM_PRINT(_)
114 #define IS_ALWAYS_MATCH(_)
115 #define MATCH_INDEX(_)
116 #define IS_VTABLE_MATCH(_)
118 #define END_PROTOCOL_ENTRY
119 #define END_PROTOCOL_ENTRY_FLUSH
120 #define END_PROTOCOL_ENTRY_HEAVY
122 #include <mono/sgen/sgen-protocol-def.h>
128 size_t size_read
= read_stream (stream
, data
, size
);
129 g_assert (size_read
== size
);
136 is_always_match (int type
)
138 switch (TYPE (type
)) {
139 #define BEGIN_PROTOCOL_ENTRY0(method) \
140 case PROTOCOL_ID(method):
141 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
142 case PROTOCOL_ID(method):
143 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
144 case PROTOCOL_ID(method):
145 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
146 case PROTOCOL_ID(method):
147 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
148 case PROTOCOL_ID(method):
149 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
150 case PROTOCOL_ID(method):
151 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
152 case PROTOCOL_ID(method):
154 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
155 BEGIN_PROTOCOL_ENTRY0 (method)
156 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
157 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
158 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
159 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
160 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
161 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
162 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
163 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
164 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
165 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
166 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
167 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
169 #define DEFAULT_PRINT()
170 #define CUSTOM_PRINT(_)
172 #define IS_ALWAYS_MATCH(is_always_match) \
173 return is_always_match;
174 #define MATCH_INDEX(_)
175 #define IS_VTABLE_MATCH(_)
177 #define END_PROTOCOL_ENTRY
178 #define END_PROTOCOL_ENTRY_FLUSH
179 #define END_PROTOCOL_ENTRY_HEAVY
181 #include <mono/sgen/sgen-protocol-def.h>
189 enum { NO_COLOR
= -1 };
195 /* The index of the ANSI color with which to highlight
196 * this entry, or NO_COLOR for no highlighting.
203 #define TYPE_LONGLONG 1
205 #define TYPE_POINTER 3
209 print_entry_content (int entries_size
, PrintEntry
*entries
, gboolean color_output
)
212 for (i
= 0; i
< entries_size
; ++i
) {
213 printf ("%s%s ", i
== 0 ? "" : " ", entries
[i
].name
);
214 if (color_output
&& entries
[i
].color
!= NO_COLOR
)
215 /* Set foreground color, excluding black & white. */
216 printf ("\x1B[%dm", 31 + (entries
[i
].color
% 6));
217 switch (entries
[i
].type
) {
219 printf ("%d", *(int*) entries
[i
].data
);
222 printf ("%lld", *(long long*) entries
[i
].data
);
225 printf ("%" MWORD_FORMAT_SPEC_D
, *(mword
*) entries
[i
].data
);
228 printf ("0x%" MWORD_FORMAT_SPEC_P
, *(mword
*) entries
[i
].data
);
231 printf ("%s", *(gboolean
*) entries
[i
].data
? "true" : "false");
236 if (color_output
&& entries
[i
].color
!= NO_COLOR
)
237 /* Reset foreground color to default. */
243 index_color (int index
, int num_nums
, int *match_indices
)
246 for (result
= 0; result
< num_nums
+ 1; ++result
)
247 if (index
== match_indices
[result
])
253 print_entry (int type
, void *data
, int num_nums
, int *match_indices
, gboolean color_output
, unsigned char worker_index
)
255 const char *always_prefix
= is_always_match (type
) ? " " : "";
257 printf ("w%-2d%s ", worker_index
, always_prefix
);
259 printf (" %s ", always_prefix
);
261 switch (TYPE (type
)) {
263 #define BEGIN_PROTOCOL_ENTRY0(method) \
264 case PROTOCOL_ID(method): { \
265 const int pes_size G_GNUC_UNUSED = 0; \
266 PrintEntry pes [1] G_GNUC_UNUSED; \
267 printf ("%s", &#method [sizeof ("binary_protocol_") - 1]);
268 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
269 case PROTOCOL_ID(method): { \
270 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
271 const int pes_size G_GNUC_UNUSED = 1; \
272 PrintEntry pes [1] G_GNUC_UNUSED; \
274 pes [0].name = #f1; \
275 pes [0].data = &entry->f1; \
276 pes [0].color = index_color(0, num_nums, match_indices); \
277 printf ("%s ", #method + strlen ("binary_protocol_"));
278 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
279 case PROTOCOL_ID(method): { \
280 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
281 const int pes_size G_GNUC_UNUSED = 2; \
282 PrintEntry pes [2] G_GNUC_UNUSED; \
284 pes [0].name = #f1; \
285 pes [0].data = &entry->f1; \
286 pes [0].color = index_color(0, num_nums, match_indices); \
288 pes [1].name = #f2; \
289 pes [1].data = &entry->f2; \
290 pes [1].color = index_color(1, num_nums, match_indices); \
291 printf ("%s ", #method + strlen ("binary_protocol_"));
292 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
293 case PROTOCOL_ID(method): { \
294 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
295 const int pes_size G_GNUC_UNUSED = 3; \
296 PrintEntry pes [3] G_GNUC_UNUSED; \
298 pes [0].name = #f1; \
299 pes [0].data = &entry->f1; \
300 pes [0].color = index_color(0, num_nums, match_indices); \
302 pes [1].name = #f2; \
303 pes [1].data = &entry->f2; \
304 pes [1].color = index_color(1, num_nums, match_indices); \
306 pes [2].name = #f3; \
307 pes [2].data = &entry->f3; \
308 pes [2].color = index_color(2, num_nums, match_indices); \
309 printf ("%s ", #method + strlen ("binary_protocol_"));
310 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
311 case PROTOCOL_ID(method): { \
312 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
313 const int pes_size G_GNUC_UNUSED = 4; \
314 PrintEntry pes [4] G_GNUC_UNUSED; \
316 pes [0].name = #f1; \
317 pes [0].data = &entry->f1; \
318 pes [0].color = index_color(0, num_nums, match_indices); \
320 pes [1].name = #f2; \
321 pes [1].data = &entry->f2; \
322 pes [1].color = index_color(1, num_nums, match_indices); \
324 pes [2].name = #f3; \
325 pes [2].data = &entry->f3; \
326 pes [2].color = index_color(2, num_nums, match_indices); \
328 pes [3].name = #f4; \
329 pes [3].data = &entry->f4; \
330 pes [3].color = index_color(3, num_nums, match_indices); \
331 printf ("%s ", #method + strlen ("binary_protocol_"));
332 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
333 case PROTOCOL_ID(method): { \
334 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
335 const int pes_size G_GNUC_UNUSED = 5; \
336 PrintEntry pes [5] G_GNUC_UNUSED; \
338 pes [0].name = #f1; \
339 pes [0].data = &entry->f1; \
340 pes [0].color = index_color(0, num_nums, match_indices); \
342 pes [1].name = #f2; \
343 pes [1].data = &entry->f2; \
344 pes [1].color = index_color(1, num_nums, match_indices); \
346 pes [2].name = #f3; \
347 pes [2].data = &entry->f3; \
348 pes [2].color = index_color(2, num_nums, match_indices); \
350 pes [3].name = #f4; \
351 pes [3].data = &entry->f4; \
352 pes [3].color = index_color(3, num_nums, match_indices); \
354 pes [4].name = #f5; \
355 pes [4].data = &entry->f5; \
356 pes [4].color = index_color(4, num_nums, match_indices); \
357 printf ("%s ", #method + strlen ("binary_protocol_"));
358 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
359 case PROTOCOL_ID(method): { \
360 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
361 const int pes_size G_GNUC_UNUSED = 6; \
362 PrintEntry pes [6] G_GNUC_UNUSED; \
364 pes [0].name = #f1; \
365 pes [0].data = &entry->f1; \
366 pes [0].color = index_color(0, num_nums, match_indices); \
368 pes [1].name = #f2; \
369 pes [1].data = &entry->f2; \
370 pes [1].color = index_color(1, num_nums, match_indices); \
372 pes [2].name = #f3; \
373 pes [2].data = &entry->f3; \
374 pes [2].color = index_color(2, num_nums, match_indices); \
376 pes [3].name = #f4; \
377 pes [3].data = &entry->f4; \
378 pes [3].color = index_color(3, num_nums, match_indices); \
380 pes [4].name = #f5; \
381 pes [4].data = &entry->f5; \
382 pes [4].color = index_color(4, num_nums, match_indices); \
384 pes [5].name = #f6; \
385 pes [5].data = &entry->f6; \
386 pes [5].color = index_color(5, num_nums, match_indices); \
387 printf ("%s ", #method + strlen ("binary_protocol_"));
389 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
390 BEGIN_PROTOCOL_ENTRY0 (method)
391 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
392 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
393 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
394 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
395 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
396 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
397 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
398 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
399 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
400 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
401 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
402 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
404 #define DEFAULT_PRINT() \
405 print_entry_content (pes_size, pes, color_output);
406 #define CUSTOM_PRINT(print) \
409 #define IS_ALWAYS_MATCH(_)
410 #define MATCH_INDEX(_)
411 #define IS_VTABLE_MATCH(_)
413 #define END_PROTOCOL_ENTRY \
417 #define END_PROTOCOL_ENTRY_FLUSH \
419 #define END_PROTOCOL_ENTRY_HEAVY \
422 #include <mono/sgen/sgen-protocol-def.h>
434 #define TYPE_LONGLONG long long
435 #define TYPE_SIZE mword
436 #define TYPE_POINTER mword
439 matches_interval (mword ptr
, mword start
, int size
)
441 return ptr
>= start
&& ptr
< start
+ size
;
444 /* Returns the index of the field where a match was found,
445 * BINARY_PROTOCOL_NO_MATCH for no match, or
446 * BINARY_PROTOCOL_MATCH for a match with no index.
449 match_index (mword ptr
, int type
, void *data
)
451 switch (TYPE (type
)) {
453 #define BEGIN_PROTOCOL_ENTRY0(method) \
454 case PROTOCOL_ID (method): {
455 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
456 case PROTOCOL_ID (method): { \
457 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
458 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
459 case PROTOCOL_ID (method): { \
460 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
461 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
462 case PROTOCOL_ID (method): { \
463 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
464 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
465 case PROTOCOL_ID (method): { \
466 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
467 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
468 case PROTOCOL_ID (method): { \
469 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
470 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
471 case PROTOCOL_ID (method): { \
472 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
474 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
475 BEGIN_PROTOCOL_ENTRY0 (method)
476 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
477 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
478 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
479 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
480 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
481 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
482 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
483 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
484 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
485 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
486 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
487 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
489 #define DEFAULT_PRINT()
490 #define CUSTOM_PRINT(_)
492 #define IS_ALWAYS_MATCH(_)
493 #define MATCH_INDEX(block) \
495 #define IS_VTABLE_MATCH(_)
497 #define END_PROTOCOL_ENTRY \
500 #define END_PROTOCOL_ENTRY_FLUSH \
502 #define END_PROTOCOL_ENTRY_HEAVY \
505 #include <mono/sgen/sgen-protocol-def.h>
514 is_vtable_match (mword ptr
, int type
, void *data
)
516 switch (TYPE (type
)) {
518 #define BEGIN_PROTOCOL_ENTRY0(method) \
519 case PROTOCOL_ID (method): {
520 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
521 case PROTOCOL_ID (method): { \
522 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
523 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
524 case PROTOCOL_ID (method): { \
525 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
526 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
527 case PROTOCOL_ID (method): { \
528 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
529 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
530 case PROTOCOL_ID (method): { \
531 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
532 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
533 case PROTOCOL_ID (method): { \
534 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
535 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
536 case PROTOCOL_ID (method): { \
537 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
539 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
540 BEGIN_PROTOCOL_ENTRY0 (method)
541 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
542 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
543 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
544 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
545 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
546 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
547 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
548 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
549 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
550 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
551 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
552 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
554 #define DEFAULT_PRINT()
555 #define CUSTOM_PRINT(_)
557 #define IS_ALWAYS_MATCH(_)
558 #define MATCH_INDEX(block) \
560 #define IS_VTABLE_MATCH(_)
562 #define END_PROTOCOL_ENTRY \
565 #define END_PROTOCOL_ENTRY_FLUSH \
567 #define END_PROTOCOL_ENTRY_HEAVY \
570 #include <mono/sgen/sgen-protocol-def.h>
584 sgen_binary_protocol_read_header (EntryStream
*stream
)
586 #ifdef BINPROT_HAS_HEADER
587 char data
[MAX_ENTRY_SIZE
];
588 int type
= read_entry (stream
, data
, NULL
);
589 if (type
== SGEN_PROTOCOL_EOF
)
591 if (type
== PROTOCOL_ID (binary_protocol_header
)) {
592 PROTOCOL_STRUCT (binary_protocol_header
) * str
= (PROTOCOL_STRUCT (binary_protocol_header
) *) data
;
593 if (str
->check
== PROTOCOL_HEADER_CHECK
&& str
->ptr_size
== BINPROT_SIZEOF_VOID_P
) {
594 if (str
->version
> PROTOCOL_HEADER_VERSION
) {
595 fprintf (stderr
, "The file contains a newer version %d. We support up to %d. Please update.\n", str
->version
, PROTOCOL_HEADER_VERSION
);
598 file_version
= str
->version
;
605 * This implementation doesn't account for the presence of a header,
606 * reading all the entries with the default configuration of the host
607 * machine. It has to be used only after all other implementations
608 * fail to identify a header, for backward compatibility.
614 #define CONC(A, B) CONC_(A, B)
615 #define CONC_(A, B) A##B
616 #define GREP_ENTRIES_FUNCTION_NAME CONC(sgen_binary_protocol_grep_entries, CONC(ARCH_SUFFIX,PACKED_SUFFIX))
619 GREP_ENTRIES_FUNCTION_NAME (EntryStream
*stream
, int num_nums
, long nums
[], int num_vtables
, long vtables
[],
620 gboolean dump_all
, gboolean pause_times
, gboolean color_output
, unsigned long long first_entry_to_consider
)
623 unsigned char worker_index
;
624 void *data
= g_malloc0 (MAX_ENTRY_SIZE
);
626 gboolean pause_times_stopped
= FALSE
;
627 gboolean pause_times_concurrent
= FALSE
;
628 gboolean pause_times_finish
= FALSE
;
629 long long pause_times_ts
= 0;
630 unsigned long long entry_index
;
632 if (!sgen_binary_protocol_read_header (stream
))
636 while ((type
= read_entry (stream
, data
, &worker_index
)) != SGEN_PROTOCOL_EOF
) {
637 if (entry_index
< first_entry_to_consider
)
641 case PROTOCOL_ID (binary_protocol_world_stopping
): {
642 PROTOCOL_STRUCT (binary_protocol_world_stopping
) *entry
= (PROTOCOL_STRUCT (binary_protocol_world_stopping
)*)data
;
643 assert (!pause_times_stopped
);
644 pause_times_concurrent
= FALSE
;
645 pause_times_finish
= FALSE
;
646 pause_times_ts
= entry
->timestamp
;
647 pause_times_stopped
= TRUE
;
650 case PROTOCOL_ID (binary_protocol_concurrent_finish
):
651 pause_times_finish
= TRUE
;
652 case PROTOCOL_ID (binary_protocol_concurrent_start
):
653 case PROTOCOL_ID (binary_protocol_concurrent_update
):
654 pause_times_concurrent
= TRUE
;
656 case PROTOCOL_ID (binary_protocol_world_restarted
): {
657 PROTOCOL_STRUCT (binary_protocol_world_restarted
) *entry
= (PROTOCOL_STRUCT (binary_protocol_world_restarted
)*)data
;
658 assert (pause_times_stopped
);
659 printf ("pause-time %d %d %d %lld %lld\n",
661 pause_times_concurrent
,
663 entry
->timestamp
- pause_times_ts
,
665 pause_times_stopped
= FALSE
;
670 int match_indices
[num_nums
+ 1];
671 gboolean match
= is_always_match (type
);
672 match_indices
[num_nums
] = num_nums
== 0 ? match_index (0, type
, data
) : BINARY_PROTOCOL_NO_MATCH
;
673 match
= match_indices
[num_nums
] != BINARY_PROTOCOL_NO_MATCH
;
674 for (i
= 0; i
< num_nums
; ++i
) {
675 match_indices
[i
] = match_index ((mword
) nums
[i
], type
, data
);
676 match
= match
|| match_indices
[i
] != BINARY_PROTOCOL_NO_MATCH
;
679 for (i
= 0; i
< num_vtables
; ++i
) {
680 if (is_vtable_match ((mword
) vtables
[i
], type
, data
)) {
686 if (match
|| dump_all
)
687 printf ("%12lld ", entry_index
);
689 printf (match
? "* " : " ");
690 if (match
|| dump_all
)
691 print_entry (type
, data
, num_nums
, match_indices
, color_output
, worker_index
);