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>
187 enum { NO_COLOR
= -1 };
193 /* The index of the ANSI color with which to highlight
194 * this entry, or NO_COLOR for no highlighting.
201 #define TYPE_LONGLONG 1
203 #define TYPE_POINTER 3
207 print_entry_content (int entries_size
, PrintEntry
*entries
, gboolean color_output
)
210 for (i
= 0; i
< entries_size
; ++i
) {
211 printf ("%s%s ", i
== 0 ? "" : " ", entries
[i
].name
);
212 if (color_output
&& entries
[i
].color
!= NO_COLOR
)
213 /* Set foreground color, excluding black & white. */
214 printf ("\x1B[%dm", 31 + (entries
[i
].color
% 6));
215 switch (entries
[i
].type
) {
217 printf ("%d", *(int*) entries
[i
].data
);
220 printf ("%lld", *(long long*) entries
[i
].data
);
223 printf ("%" MWORD_FORMAT_SPEC_D
, *(mword
*) entries
[i
].data
);
226 printf ("0x%" MWORD_FORMAT_SPEC_P
, *(mword
*) entries
[i
].data
);
229 printf ("%s", *(gboolean
*) entries
[i
].data
? "true" : "false");
234 if (color_output
&& entries
[i
].color
!= NO_COLOR
)
235 /* Reset foreground color to default. */
241 index_color (int index
, int num_nums
, int *match_indices
)
244 for (result
= 0; result
< num_nums
+ 1; ++result
)
245 if (index
== match_indices
[result
])
251 print_entry (int type
, void *data
, int num_nums
, int *match_indices
, gboolean color_output
, unsigned char worker_index
)
253 const char *always_prefix
= is_always_match (type
) ? " " : "";
255 printf ("w%-2d%s ", worker_index
, always_prefix
);
257 printf (" %s ", always_prefix
);
259 switch (TYPE (type
)) {
261 #define BEGIN_PROTOCOL_ENTRY0(method) \
262 case PROTOCOL_ID(method): { \
263 const int pes_size G_GNUC_UNUSED = 0; \
264 PrintEntry pes [1] G_GNUC_UNUSED; \
265 printf ("%s", #method + strlen ("binary_protocol_"));
266 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
267 case PROTOCOL_ID(method): { \
268 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
269 const int pes_size G_GNUC_UNUSED = 1; \
270 PrintEntry pes [1] G_GNUC_UNUSED; \
272 pes [0].name = #f1; \
273 pes [0].data = &entry->f1; \
274 pes [0].color = index_color(0, num_nums, match_indices); \
275 printf ("%s ", #method + strlen ("binary_protocol_"));
276 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
277 case PROTOCOL_ID(method): { \
278 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
279 const int pes_size G_GNUC_UNUSED = 2; \
280 PrintEntry pes [2] G_GNUC_UNUSED; \
282 pes [0].name = #f1; \
283 pes [0].data = &entry->f1; \
284 pes [0].color = index_color(0, num_nums, match_indices); \
286 pes [1].name = #f2; \
287 pes [1].data = &entry->f2; \
288 pes [1].color = index_color(1, num_nums, match_indices); \
289 printf ("%s ", #method + strlen ("binary_protocol_"));
290 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
291 case PROTOCOL_ID(method): { \
292 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
293 const int pes_size G_GNUC_UNUSED = 3; \
294 PrintEntry pes [3] G_GNUC_UNUSED; \
296 pes [0].name = #f1; \
297 pes [0].data = &entry->f1; \
298 pes [0].color = index_color(0, num_nums, match_indices); \
300 pes [1].name = #f2; \
301 pes [1].data = &entry->f2; \
302 pes [1].color = index_color(1, num_nums, match_indices); \
304 pes [2].name = #f3; \
305 pes [2].data = &entry->f3; \
306 pes [2].color = index_color(2, num_nums, match_indices); \
307 printf ("%s ", #method + strlen ("binary_protocol_"));
308 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
309 case PROTOCOL_ID(method): { \
310 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
311 const int pes_size G_GNUC_UNUSED = 4; \
312 PrintEntry pes [4] G_GNUC_UNUSED; \
314 pes [0].name = #f1; \
315 pes [0].data = &entry->f1; \
316 pes [0].color = index_color(0, num_nums, match_indices); \
318 pes [1].name = #f2; \
319 pes [1].data = &entry->f2; \
320 pes [1].color = index_color(1, num_nums, match_indices); \
322 pes [2].name = #f3; \
323 pes [2].data = &entry->f3; \
324 pes [2].color = index_color(2, num_nums, match_indices); \
326 pes [3].name = #f4; \
327 pes [3].data = &entry->f4; \
328 pes [3].color = index_color(3, num_nums, match_indices); \
329 printf ("%s ", #method + strlen ("binary_protocol_"));
330 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
331 case PROTOCOL_ID(method): { \
332 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
333 const int pes_size G_GNUC_UNUSED = 5; \
334 PrintEntry pes [5] G_GNUC_UNUSED; \
336 pes [0].name = #f1; \
337 pes [0].data = &entry->f1; \
338 pes [0].color = index_color(0, num_nums, match_indices); \
340 pes [1].name = #f2; \
341 pes [1].data = &entry->f2; \
342 pes [1].color = index_color(1, num_nums, match_indices); \
344 pes [2].name = #f3; \
345 pes [2].data = &entry->f3; \
346 pes [2].color = index_color(2, num_nums, match_indices); \
348 pes [3].name = #f4; \
349 pes [3].data = &entry->f4; \
350 pes [3].color = index_color(3, num_nums, match_indices); \
352 pes [4].name = #f5; \
353 pes [4].data = &entry->f5; \
354 pes [4].color = index_color(4, num_nums, match_indices); \
355 printf ("%s ", #method + strlen ("binary_protocol_"));
356 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
357 case PROTOCOL_ID(method): { \
358 PROTOCOL_STRUCT (method) *entry = (PROTOCOL_STRUCT (method)*)data; \
359 const int pes_size G_GNUC_UNUSED = 6; \
360 PrintEntry pes [6] G_GNUC_UNUSED; \
362 pes [0].name = #f1; \
363 pes [0].data = &entry->f1; \
364 pes [0].color = index_color(0, num_nums, match_indices); \
366 pes [1].name = #f2; \
367 pes [1].data = &entry->f2; \
368 pes [1].color = index_color(1, num_nums, match_indices); \
370 pes [2].name = #f3; \
371 pes [2].data = &entry->f3; \
372 pes [2].color = index_color(2, num_nums, match_indices); \
374 pes [3].name = #f4; \
375 pes [3].data = &entry->f4; \
376 pes [3].color = index_color(3, num_nums, match_indices); \
378 pes [4].name = #f5; \
379 pes [4].data = &entry->f5; \
380 pes [4].color = index_color(4, num_nums, match_indices); \
382 pes [5].name = #f6; \
383 pes [5].data = &entry->f6; \
384 pes [5].color = index_color(5, num_nums, match_indices); \
385 printf ("%s ", #method + strlen ("binary_protocol_"));
387 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
388 BEGIN_PROTOCOL_ENTRY0 (method)
389 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
390 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
391 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
392 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
393 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
394 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
395 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
396 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
397 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
398 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
399 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
400 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
402 #define DEFAULT_PRINT() \
403 print_entry_content (pes_size, pes, color_output);
404 #define CUSTOM_PRINT(print) \
407 #define IS_ALWAYS_MATCH(_)
408 #define MATCH_INDEX(_)
409 #define IS_VTABLE_MATCH(_)
411 #define END_PROTOCOL_ENTRY \
415 #define END_PROTOCOL_ENTRY_FLUSH \
417 #define END_PROTOCOL_ENTRY_HEAVY \
420 #include <mono/sgen/sgen-protocol-def.h>
432 #define TYPE_LONGLONG long long
433 #define TYPE_SIZE mword
434 #define TYPE_POINTER mword
437 matches_interval (mword ptr
, mword start
, int size
)
439 return ptr
>= start
&& ptr
< start
+ size
;
442 /* Returns the index of the field where a match was found,
443 * BINARY_PROTOCOL_NO_MATCH for no match, or
444 * BINARY_PROTOCOL_MATCH for a match with no index.
447 match_index (mword ptr
, int type
, void *data
)
449 switch (TYPE (type
)) {
451 #define BEGIN_PROTOCOL_ENTRY0(method) \
452 case PROTOCOL_ID (method): {
453 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
454 case PROTOCOL_ID (method): { \
455 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
456 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
457 case PROTOCOL_ID (method): { \
458 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
459 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
460 case PROTOCOL_ID (method): { \
461 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
462 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
463 case PROTOCOL_ID (method): { \
464 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
465 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
466 case PROTOCOL_ID (method): { \
467 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
468 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
469 case PROTOCOL_ID (method): { \
470 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
472 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
473 BEGIN_PROTOCOL_ENTRY0 (method)
474 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
475 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
476 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
477 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
478 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
479 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
480 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
481 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
482 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
483 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
484 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
485 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
487 #define DEFAULT_PRINT()
488 #define CUSTOM_PRINT(_)
490 #define IS_ALWAYS_MATCH(_)
491 #define MATCH_INDEX(block) \
493 #define IS_VTABLE_MATCH(_)
495 #define END_PROTOCOL_ENTRY \
498 #define END_PROTOCOL_ENTRY_FLUSH \
500 #define END_PROTOCOL_ENTRY_HEAVY \
503 #include <mono/sgen/sgen-protocol-def.h>
510 is_vtable_match (mword ptr
, int type
, void *data
)
512 switch (TYPE (type
)) {
514 #define BEGIN_PROTOCOL_ENTRY0(method) \
515 case PROTOCOL_ID (method): {
516 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
517 case PROTOCOL_ID (method): { \
518 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
519 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
520 case PROTOCOL_ID (method): { \
521 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
522 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
523 case PROTOCOL_ID (method): { \
524 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
525 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
526 case PROTOCOL_ID (method): { \
527 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
528 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
529 case PROTOCOL_ID (method): { \
530 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
531 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
532 case PROTOCOL_ID (method): { \
533 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = (PROTOCOL_STRUCT (method)*)data;
535 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
536 BEGIN_PROTOCOL_ENTRY0 (method)
537 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
538 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
539 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
540 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
541 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
542 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
543 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
544 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
545 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
546 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
547 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
548 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
550 #define DEFAULT_PRINT()
551 #define CUSTOM_PRINT(_)
553 #define IS_ALWAYS_MATCH(_)
554 #define MATCH_INDEX(block) \
556 #define IS_VTABLE_MATCH(_)
558 #define END_PROTOCOL_ENTRY \
561 #define END_PROTOCOL_ENTRY_FLUSH \
563 #define END_PROTOCOL_ENTRY_HEAVY \
566 #include <mono/sgen/sgen-protocol-def.h>
578 sgen_binary_protocol_read_header (EntryStream
*stream
)
580 #ifdef BINPROT_HAS_HEADER
581 char data
[MAX_ENTRY_SIZE
];
582 int type
= read_entry (stream
, data
, NULL
);
583 if (type
== SGEN_PROTOCOL_EOF
)
585 if (type
== PROTOCOL_ID (binary_protocol_header
)) {
586 PROTOCOL_STRUCT (binary_protocol_header
) * str
= (PROTOCOL_STRUCT (binary_protocol_header
) *) data
;
587 if (str
->check
== PROTOCOL_HEADER_CHECK
&& str
->ptr_size
== BINPROT_SIZEOF_VOID_P
) {
588 if (str
->version
> PROTOCOL_HEADER_VERSION
) {
589 fprintf (stderr
, "The file contains a newer version %d. We support up to %d. Please update.\n", str
->version
, PROTOCOL_HEADER_VERSION
);
592 file_version
= str
->version
;
599 * This implementation doesn't account for the presence of a header,
600 * reading all the entries with the default configuration of the host
601 * machine. It has to be used only after all other implementations
602 * fail to identify a header, for backward compatibility.
608 #define CONC(A, B) CONC_(A, B)
609 #define CONC_(A, B) A##B
610 #define GREP_ENTRIES_FUNCTION_NAME CONC(sgen_binary_protocol_grep_entries, CONC(ARCH_SUFFIX,PACKED_SUFFIX))
613 GREP_ENTRIES_FUNCTION_NAME (EntryStream
*stream
, int num_nums
, long nums
[], int num_vtables
, long vtables
[],
614 gboolean dump_all
, gboolean pause_times
, gboolean color_output
, unsigned long long first_entry_to_consider
)
617 unsigned char worker_index
;
618 void *data
= g_malloc0 (MAX_ENTRY_SIZE
);
620 gboolean pause_times_stopped
= FALSE
;
621 gboolean pause_times_concurrent
= FALSE
;
622 gboolean pause_times_finish
= FALSE
;
623 long long pause_times_ts
= 0;
624 unsigned long long entry_index
;
626 if (!sgen_binary_protocol_read_header (stream
))
630 while ((type
= read_entry (stream
, data
, &worker_index
)) != SGEN_PROTOCOL_EOF
) {
631 if (entry_index
< first_entry_to_consider
)
635 case PROTOCOL_ID (binary_protocol_world_stopping
): {
636 PROTOCOL_STRUCT (binary_protocol_world_stopping
) *entry
= (PROTOCOL_STRUCT (binary_protocol_world_stopping
)*)data
;
637 assert (!pause_times_stopped
);
638 pause_times_concurrent
= FALSE
;
639 pause_times_finish
= FALSE
;
640 pause_times_ts
= entry
->timestamp
;
641 pause_times_stopped
= TRUE
;
644 case PROTOCOL_ID (binary_protocol_concurrent_finish
):
645 pause_times_finish
= TRUE
;
646 case PROTOCOL_ID (binary_protocol_concurrent_start
):
647 case PROTOCOL_ID (binary_protocol_concurrent_update
):
648 pause_times_concurrent
= TRUE
;
650 case PROTOCOL_ID (binary_protocol_world_restarted
): {
651 PROTOCOL_STRUCT (binary_protocol_world_restarted
) *entry
= (PROTOCOL_STRUCT (binary_protocol_world_restarted
)*)data
;
652 assert (pause_times_stopped
);
653 printf ("pause-time %d %d %d %lld %lld\n",
655 pause_times_concurrent
,
657 entry
->timestamp
- pause_times_ts
,
659 pause_times_stopped
= FALSE
;
664 int match_indices
[num_nums
+ 1];
665 gboolean match
= is_always_match (type
);
666 match_indices
[num_nums
] = num_nums
== 0 ? match_index (0, type
, data
) : BINARY_PROTOCOL_NO_MATCH
;
667 match
= match_indices
[num_nums
] != BINARY_PROTOCOL_NO_MATCH
;
668 for (i
= 0; i
< num_nums
; ++i
) {
669 match_indices
[i
] = match_index ((mword
) nums
[i
], type
, data
);
670 match
= match
|| match_indices
[i
] != BINARY_PROTOCOL_NO_MATCH
;
673 for (i
= 0; i
< num_vtables
; ++i
) {
674 if (is_vtable_match ((mword
) vtables
[i
], type
, data
)) {
680 if (match
|| dump_all
)
681 printf ("%12lld ", entry_index
);
683 printf (match
? "* " : " ");
684 if (match
|| dump_all
)
685 print_entry (type
, data
, num_nums
, match_indices
, color_output
, worker_index
);