8 #define SGEN_BINARY_PROTOCOL
11 #include <mono/metadata/sgen-protocol.h>
13 #define SGEN_PROTOCOL_EOF 255
15 #define TYPE(t) ((t) & 0x7f)
16 #define WORKER(t) ((t) & 0x80)
18 #define MAX_ENTRY_SIZE (1 << 10)
19 #define BUFFER_SIZE (1 << 20)
29 init_stream (EntryStream *stream, int file)
32 stream->buffer = g_malloc0 (BUFFER_SIZE);
33 stream->end = stream->buffer + BUFFER_SIZE;
34 stream->pos = stream->end;
38 close_stream (EntryStream *stream)
40 g_free (stream->buffer);
44 refill_stream (EntryStream *in, size_t size)
46 size_t remainder = in->end - in->pos;
49 g_assert (in->pos >= in->buffer);
50 if (in->pos + size <= in->end)
52 memmove (in->buffer, in->pos, remainder);
54 refilled = read (in->file, in->buffer + remainder, BUFFER_SIZE - remainder);
57 g_assert (refilled + remainder <= BUFFER_SIZE);
58 in->end = in->buffer + refilled + remainder;
59 return in->end - in->buffer >= size;
63 read_stream (EntryStream *stream, void *out, size_t size)
65 if (refill_stream (stream, size)) {
66 memcpy (out, stream->pos, size);
74 read_entry (EntryStream *stream, void *data)
79 if (read_stream (stream, &type, 1) <= 0)
80 return SGEN_PROTOCOL_EOF;
81 switch (TYPE (type)) {
83 #define BEGIN_PROTOCOL_ENTRY0(method) \
84 case PROTOCOL_ID(method): size = 0; break;
85 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
86 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
87 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
88 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
89 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
90 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
91 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
92 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
93 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
94 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
95 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
96 case PROTOCOL_ID(method): size = sizeof (PROTOCOL_STRUCT(method)); break;
98 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
99 BEGIN_PROTOCOL_ENTRY0 (method)
100 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
101 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
102 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
103 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
104 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
105 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
106 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
107 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
108 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
109 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
110 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
111 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
115 #define DEFAULT_PRINT()
116 #define CUSTOM_PRINT(_)
118 #define IS_ALWAYS_MATCH(_)
119 #define MATCH_INDEX(_)
120 #define IS_VTABLE_MATCH(_)
122 #define END_PROTOCOL_ENTRY
123 #define END_PROTOCOL_ENTRY_HEAVY
125 #include <mono/metadata/sgen-protocol-def.h>
131 size_t size_read = read_stream (stream, data, size);
132 g_assert (size_read == size);
139 is_always_match (int type)
141 switch (TYPE (type)) {
142 #define BEGIN_PROTOCOL_ENTRY0(method) \
143 case PROTOCOL_ID(method):
144 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
145 case PROTOCOL_ID(method):
146 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
147 case PROTOCOL_ID(method):
148 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
149 case PROTOCOL_ID(method):
150 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
151 case PROTOCOL_ID(method):
152 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
153 case PROTOCOL_ID(method):
154 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
155 case PROTOCOL_ID(method):
157 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
158 BEGIN_PROTOCOL_ENTRY0 (method)
159 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
160 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
161 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
162 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
163 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
164 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
165 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
166 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
167 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
168 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
169 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
170 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
174 #define DEFAULT_PRINT()
175 #define CUSTOM_PRINT(_)
177 #define IS_ALWAYS_MATCH(is_always_match) \
178 return is_always_match;
179 #define MATCH_INDEX(_)
180 #define IS_VTABLE_MATCH(_)
182 #define END_PROTOCOL_ENTRY
183 #define END_PROTOCOL_ENTRY_HEAVY
185 #include <mono/metadata/sgen-protocol-def.h>
191 #define WORKER_PREFIX(t) (WORKER ((t)) ? "w" : " ")
193 enum { NO_COLOR = -1 };
199 /* The index of the ANSI color with which to highlight
200 * this entry, or NO_COLOR for no highlighting.
207 #define TYPE_LONGLONG 1
209 #define TYPE_POINTER 3
213 print_entry_content (int entries_size, PrintEntry *entries, gboolean color_output)
216 for (i = 0; i < entries_size; ++i) {
217 printf ("%s%s ", i == 0 ? "" : " ", entries [i].name);
218 if (color_output && entries [i].color != NO_COLOR)
219 /* Set foreground color, excluding black & white. */
220 printf ("\x1B[%dm", 31 + (entries [i].color % 6));
221 switch (entries [i].type) {
223 printf ("%d", *(int*) entries [i].data);
226 printf ("%lld", *(long long*) entries [i].data);
229 printf ("%lu", *(size_t*) entries [i].data);
232 printf ("%p", *(gpointer*) entries [i].data);
235 printf ("%s", *(gboolean*) entries [i].data ? "true" : "false");
240 if (color_output && entries [i].color != NO_COLOR)
241 /* Reset foreground color to default. */
247 index_color (int index, int num_nums, int *match_indices)
250 for (result = 0; result < num_nums + 1; ++result)
251 if (index == match_indices [result])
257 print_entry (int type, void *data, int num_nums, int *match_indices, gboolean color_output)
259 const char *always_prefix = is_always_match (type) ? " " : "";
260 printf ("%s%s ", WORKER_PREFIX (type), always_prefix);
262 switch (TYPE (type)) {
264 #define BEGIN_PROTOCOL_ENTRY0(method) \
265 case PROTOCOL_ID(method): { \
266 const int pes_size G_GNUC_UNUSED = 0; \
267 PrintEntry pes [1] G_GNUC_UNUSED; \
268 printf ("%s", #method + strlen ("binary_protocol_"));
269 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
270 case PROTOCOL_ID(method): { \
271 PROTOCOL_STRUCT (method) *entry = data; \
272 const int pes_size G_GNUC_UNUSED = 1; \
273 PrintEntry pes [1] G_GNUC_UNUSED; \
275 pes [0].name = #f1; \
276 pes [0].data = &entry->f1; \
277 pes [0].color = index_color(0, num_nums, match_indices); \
278 printf ("%s ", #method + strlen ("binary_protocol_"));
279 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
280 case PROTOCOL_ID(method): { \
281 PROTOCOL_STRUCT (method) *entry = data; \
282 const int pes_size G_GNUC_UNUSED = 2; \
283 PrintEntry pes [2] G_GNUC_UNUSED; \
285 pes [0].name = #f1; \
286 pes [0].data = &entry->f1; \
287 pes [0].color = index_color(0, num_nums, match_indices); \
289 pes [1].name = #f2; \
290 pes [1].data = &entry->f2; \
291 pes [1].color = index_color(1, num_nums, match_indices); \
292 printf ("%s ", #method + strlen ("binary_protocol_"));
293 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
294 case PROTOCOL_ID(method): { \
295 PROTOCOL_STRUCT (method) *entry = data; \
296 const int pes_size G_GNUC_UNUSED = 3; \
297 PrintEntry pes [3] G_GNUC_UNUSED; \
299 pes [0].name = #f1; \
300 pes [0].data = &entry->f1; \
301 pes [0].color = index_color(0, num_nums, match_indices); \
303 pes [1].name = #f2; \
304 pes [1].data = &entry->f2; \
305 pes [1].color = index_color(1, num_nums, match_indices); \
307 pes [2].name = #f3; \
308 pes [2].data = &entry->f3; \
309 pes [2].color = index_color(2, num_nums, match_indices); \
310 printf ("%s ", #method + strlen ("binary_protocol_"));
311 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
312 case PROTOCOL_ID(method): { \
313 PROTOCOL_STRUCT (method) *entry = data; \
314 const int pes_size G_GNUC_UNUSED = 4; \
315 PrintEntry pes [4] G_GNUC_UNUSED; \
317 pes [0].name = #f1; \
318 pes [0].data = &entry->f1; \
319 pes [0].color = index_color(0, num_nums, match_indices); \
321 pes [1].name = #f2; \
322 pes [1].data = &entry->f2; \
323 pes [1].color = index_color(1, num_nums, match_indices); \
325 pes [2].name = #f3; \
326 pes [2].data = &entry->f3; \
327 pes [2].color = index_color(2, num_nums, match_indices); \
329 pes [3].name = #f4; \
330 pes [3].data = &entry->f4; \
331 pes [3].color = index_color(3, num_nums, match_indices); \
332 printf ("%s ", #method + strlen ("binary_protocol_"));
333 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
334 case PROTOCOL_ID(method): { \
335 PROTOCOL_STRUCT (method) *entry = data; \
336 const int pes_size G_GNUC_UNUSED = 5; \
337 PrintEntry pes [5] G_GNUC_UNUSED; \
339 pes [0].name = #f1; \
340 pes [0].data = &entry->f1; \
341 pes [0].color = index_color(0, num_nums, match_indices); \
343 pes [1].name = #f2; \
344 pes [1].data = &entry->f2; \
345 pes [1].color = index_color(1, num_nums, match_indices); \
347 pes [2].name = #f3; \
348 pes [2].data = &entry->f3; \
349 pes [2].color = index_color(2, num_nums, match_indices); \
351 pes [3].name = #f4; \
352 pes [3].data = &entry->f4; \
353 pes [3].color = index_color(3, num_nums, match_indices); \
355 pes [4].name = #f5; \
356 pes [4].data = &entry->f5; \
357 pes [4].color = index_color(4, num_nums, match_indices); \
358 printf ("%s ", #method + strlen ("binary_protocol_"));
359 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
360 case PROTOCOL_ID(method): { \
361 PROTOCOL_STRUCT (method) *entry = data; \
362 const int pes_size G_GNUC_UNUSED = 6; \
363 PrintEntry pes [6] G_GNUC_UNUSED; \
365 pes [0].name = #f1; \
366 pes [0].data = &entry->f1; \
367 pes [0].color = index_color(0, num_nums, match_indices); \
369 pes [1].name = #f2; \
370 pes [1].data = &entry->f2; \
371 pes [1].color = index_color(1, num_nums, match_indices); \
373 pes [2].name = #f3; \
374 pes [2].data = &entry->f3; \
375 pes [2].color = index_color(2, num_nums, match_indices); \
377 pes [3].name = #f4; \
378 pes [3].data = &entry->f4; \
379 pes [3].color = index_color(3, num_nums, match_indices); \
381 pes [4].name = #f5; \
382 pes [4].data = &entry->f5; \
383 pes [4].color = index_color(4, num_nums, match_indices); \
385 pes [5].name = #f6; \
386 pes [5].data = &entry->f6; \
387 pes [5].color = index_color(5, num_nums, match_indices); \
388 printf ("%s ", #method + strlen ("binary_protocol_"));
390 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
391 BEGIN_PROTOCOL_ENTRY0 (method)
392 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
393 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
394 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
395 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
396 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
397 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
398 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
399 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
400 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
401 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
402 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
403 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
407 #define DEFAULT_PRINT() \
408 print_entry_content (pes_size, pes, color_output);
409 #define CUSTOM_PRINT(print) \
412 #define IS_ALWAYS_MATCH(_)
413 #define MATCH_INDEX(_)
414 #define IS_VTABLE_MATCH(_)
416 #define END_PROTOCOL_ENTRY \
420 #define END_PROTOCOL_ENTRY_HEAVY \
423 #include <mono/metadata/sgen-protocol-def.h>
435 #define TYPE_LONGLONG long long
436 #define TYPE_SIZE size_t
437 #define TYPE_POINTER gpointer
440 matches_interval (gpointer ptr, gpointer start, int size)
442 return ptr >= start && (char*)ptr < (char*)start + size;
445 /* Returns the index of the field where a match was found,
446 * BINARY_PROTOCOL_NO_MATCH for no match, or
447 * BINARY_PROTOCOL_MATCH for a match with no index.
450 match_index (gpointer ptr, int type, void *data)
452 switch (TYPE (type)) {
454 #define BEGIN_PROTOCOL_ENTRY0(method) \
455 case PROTOCOL_ID (method): {
456 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
457 case PROTOCOL_ID (method): { \
458 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
459 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
460 case PROTOCOL_ID (method): { \
461 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
462 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
463 case PROTOCOL_ID (method): { \
464 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
465 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
466 case PROTOCOL_ID (method): { \
467 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
468 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
469 case PROTOCOL_ID (method): { \
470 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
471 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
472 case PROTOCOL_ID (method): { \
473 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
475 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
476 BEGIN_PROTOCOL_ENTRY0 (method)
477 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
478 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
479 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
480 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
481 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
482 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
483 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
484 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
485 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
486 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
487 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
488 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
492 #define DEFAULT_PRINT()
493 #define CUSTOM_PRINT(_)
495 #define IS_ALWAYS_MATCH(_)
496 #define MATCH_INDEX(block) \
498 #define IS_VTABLE_MATCH(_)
500 #define END_PROTOCOL_ENTRY \
503 #define END_PROTOCOL_ENTRY_HEAVY \
506 #include <mono/metadata/sgen-protocol-def.h>
513 is_vtable_match (gpointer ptr, int type, void *data)
515 switch (TYPE (type)) {
517 #define BEGIN_PROTOCOL_ENTRY0(method) \
518 case PROTOCOL_ID (method): {
519 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
520 case PROTOCOL_ID (method): { \
521 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
522 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
523 case PROTOCOL_ID (method): { \
524 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
525 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
526 case PROTOCOL_ID (method): { \
527 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
528 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
529 case PROTOCOL_ID (method): { \
530 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
531 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
532 case PROTOCOL_ID (method): { \
533 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
534 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
535 case PROTOCOL_ID (method): { \
536 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
538 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
539 BEGIN_PROTOCOL_ENTRY0 (method)
540 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
541 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
542 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
543 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
544 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
545 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
546 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
547 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
548 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
549 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
550 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
551 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
555 #define DEFAULT_PRINT()
556 #define CUSTOM_PRINT(_)
558 #define IS_ALWAYS_MATCH(_)
559 #define MATCH_INDEX(block) \
561 #define IS_VTABLE_MATCH(_)
563 #define END_PROTOCOL_ENTRY \
566 #define END_PROTOCOL_ENTRY_HEAVY \
569 #include <mono/metadata/sgen-protocol-def.h>
581 main (int argc, char *argv[])
584 void *data = g_malloc0 (MAX_ENTRY_SIZE);
585 int num_args = argc - 1;
589 long nums [num_args];
590 long vtables [num_args];
591 gboolean dump_all = FALSE;
592 gboolean pause_times = FALSE;
593 gboolean pause_times_stopped = FALSE;
594 gboolean pause_times_concurrent = FALSE;
595 gboolean pause_times_finish = FALSE;
596 gboolean color_output = FALSE;
597 long long pause_times_ts = 0;
598 const char *input_path = NULL;
601 unsigned long long entry_index;
602 unsigned long long first_entry_to_consider = 0;
604 for (i = 0; i < num_args; ++i) {
605 char *arg = argv [i + 1];
606 char *next_arg = argv [i + 2];
607 if (!strcmp (arg, "--all")) {
609 } else if (!strcmp (arg, "--pause-times")) {
611 } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
612 vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
614 } else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
615 first_entry_to_consider = strtoull (next_arg, NULL, 10);
617 } else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
619 } else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
620 input_path = next_arg;
623 nums [num_nums++] = strtoul (arg, NULL, 16);
628 assert (!pause_times);
632 input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
633 init_stream (&stream, input_file);
635 while ((type = read_entry (&stream, data)) != SGEN_PROTOCOL_EOF) {
636 if (entry_index < first_entry_to_consider)
640 case PROTOCOL_ID (binary_protocol_world_stopping): {
641 PROTOCOL_STRUCT (binary_protocol_world_stopping) *entry = data;
642 assert (!pause_times_stopped);
643 pause_times_concurrent = FALSE;
644 pause_times_finish = FALSE;
645 pause_times_ts = entry->timestamp;
646 pause_times_stopped = TRUE;
649 case PROTOCOL_ID (binary_protocol_concurrent_finish):
650 pause_times_finish = TRUE;
651 case PROTOCOL_ID (binary_protocol_concurrent_start):
652 case PROTOCOL_ID (binary_protocol_concurrent_update):
653 pause_times_concurrent = TRUE;
655 case PROTOCOL_ID (binary_protocol_world_restarted): {
656 PROTOCOL_STRUCT (binary_protocol_world_restarted) *entry = data;
657 assert (pause_times_stopped);
658 printf ("pause-time %d %d %d %lld %lld\n",
660 pause_times_concurrent,
662 entry->timestamp - pause_times_ts,
664 pause_times_stopped = FALSE;
669 int match_indices [num_nums + 1];
670 gboolean match = is_always_match (type);
671 match_indices [num_nums] = num_nums == 0 ? match_index (NULL, type, data) : BINARY_PROTOCOL_NO_MATCH;
672 match = match_indices [num_nums] != BINARY_PROTOCOL_NO_MATCH;
673 for (i = 0; i < num_nums; ++i) {
674 match_indices [i] = match_index ((gpointer) nums [i], type, data);
675 match = match || match_indices [i] != BINARY_PROTOCOL_NO_MATCH;
678 for (i = 0; i < num_vtables; ++i) {
679 if (is_vtable_match ((gpointer) vtables [i], type, data)) {
685 if (match || dump_all)
686 printf ("%12lld ", entry_index);
688 printf (match ? "* " : " ");
689 if (match || dump_all)
690 print_entry (type, data, num_nums, match_indices, color_output);
695 close_stream (&stream);