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
212 print_entry_content (int entries_size, PrintEntry *entries, gboolean color_output)
215 for (i = 0; i < entries_size; ++i) {
216 printf ("%s%s ", i == 0 ? "" : " ", entries [i].name);
217 if (color_output && entries [i].color != NO_COLOR)
218 /* Set foreground color, excluding black & white. */
219 printf ("\x1B[%dm", 31 + (entries [i].color % 6));
220 switch (entries [i].type) {
222 printf ("%d", *(int*) entries [i].data);
225 printf ("%lld", *(long long*) entries [i].data);
228 printf ("%lu", *(size_t*) entries [i].data);
231 printf ("%p", *(gpointer*) entries [i].data);
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)
255 const char *always_prefix = is_always_match (type) ? " " : "";
256 printf ("%s%s ", WORKER_PREFIX (type), always_prefix);
258 switch (TYPE (type)) {
260 #define BEGIN_PROTOCOL_ENTRY0(method) \
261 case PROTOCOL_ID(method): { \
262 const int pes_size G_GNUC_UNUSED = 0; \
263 PrintEntry pes [1] G_GNUC_UNUSED; \
264 printf ("%s", #method + strlen ("binary_protocol_"));
265 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
266 case PROTOCOL_ID(method): { \
267 PROTOCOL_STRUCT (method) *entry = data; \
268 const int pes_size G_GNUC_UNUSED = 1; \
269 PrintEntry pes [1] G_GNUC_UNUSED; \
271 pes [0].name = #f1; \
272 pes [0].data = &entry->f1; \
273 pes [0].color = index_color(0, num_nums, match_indices); \
274 printf ("%s ", #method + strlen ("binary_protocol_"));
275 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
276 case PROTOCOL_ID(method): { \
277 PROTOCOL_STRUCT (method) *entry = data; \
278 const int pes_size G_GNUC_UNUSED = 2; \
279 PrintEntry pes [2] G_GNUC_UNUSED; \
281 pes [0].name = #f1; \
282 pes [0].data = &entry->f1; \
283 pes [0].color = index_color(0, num_nums, match_indices); \
285 pes [1].name = #f2; \
286 pes [1].data = &entry->f2; \
287 pes [1].color = index_color(1, num_nums, match_indices); \
288 printf ("%s ", #method + strlen ("binary_protocol_"));
289 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
290 case PROTOCOL_ID(method): { \
291 PROTOCOL_STRUCT (method) *entry = data; \
292 const int pes_size G_GNUC_UNUSED = 3; \
293 PrintEntry pes [3] G_GNUC_UNUSED; \
295 pes [0].name = #f1; \
296 pes [0].data = &entry->f1; \
297 pes [0].color = index_color(0, num_nums, match_indices); \
299 pes [1].name = #f2; \
300 pes [1].data = &entry->f2; \
301 pes [1].color = index_color(1, num_nums, match_indices); \
303 pes [2].name = #f3; \
304 pes [2].data = &entry->f3; \
305 pes [2].color = index_color(2, num_nums, match_indices); \
306 printf ("%s ", #method + strlen ("binary_protocol_"));
307 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
308 case PROTOCOL_ID(method): { \
309 PROTOCOL_STRUCT (method) *entry = data; \
310 const int pes_size G_GNUC_UNUSED = 4; \
311 PrintEntry pes [4] G_GNUC_UNUSED; \
313 pes [0].name = #f1; \
314 pes [0].data = &entry->f1; \
315 pes [0].color = index_color(0, num_nums, match_indices); \
317 pes [1].name = #f2; \
318 pes [1].data = &entry->f2; \
319 pes [1].color = index_color(1, num_nums, match_indices); \
321 pes [2].name = #f3; \
322 pes [2].data = &entry->f3; \
323 pes [2].color = index_color(2, num_nums, match_indices); \
325 pes [3].name = #f4; \
326 pes [3].data = &entry->f4; \
327 pes [3].color = index_color(3, num_nums, match_indices); \
328 printf ("%s ", #method + strlen ("binary_protocol_"));
329 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
330 case PROTOCOL_ID(method): { \
331 PROTOCOL_STRUCT (method) *entry = data; \
332 const int pes_size G_GNUC_UNUSED = 5; \
333 PrintEntry pes [5] G_GNUC_UNUSED; \
335 pes [0].name = #f1; \
336 pes [0].data = &entry->f1; \
337 pes [0].color = index_color(0, num_nums, match_indices); \
339 pes [1].name = #f2; \
340 pes [1].data = &entry->f2; \
341 pes [1].color = index_color(1, num_nums, match_indices); \
343 pes [2].name = #f3; \
344 pes [2].data = &entry->f3; \
345 pes [2].color = index_color(2, num_nums, match_indices); \
347 pes [3].name = #f4; \
348 pes [3].data = &entry->f4; \
349 pes [3].color = index_color(3, num_nums, match_indices); \
351 pes [4].name = #f5; \
352 pes [4].data = &entry->f5; \
353 pes [4].color = index_color(4, num_nums, match_indices); \
354 printf ("%s ", #method + strlen ("binary_protocol_"));
355 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
356 case PROTOCOL_ID(method): { \
357 PROTOCOL_STRUCT (method) *entry = data; \
358 const int pes_size G_GNUC_UNUSED = 6; \
359 PrintEntry pes [6] G_GNUC_UNUSED; \
361 pes [0].name = #f1; \
362 pes [0].data = &entry->f1; \
363 pes [0].color = index_color(0, num_nums, match_indices); \
365 pes [1].name = #f2; \
366 pes [1].data = &entry->f2; \
367 pes [1].color = index_color(1, num_nums, match_indices); \
369 pes [2].name = #f3; \
370 pes [2].data = &entry->f3; \
371 pes [2].color = index_color(2, num_nums, match_indices); \
373 pes [3].name = #f4; \
374 pes [3].data = &entry->f4; \
375 pes [3].color = index_color(3, num_nums, match_indices); \
377 pes [4].name = #f5; \
378 pes [4].data = &entry->f5; \
379 pes [4].color = index_color(4, num_nums, match_indices); \
381 pes [5].name = #f6; \
382 pes [5].data = &entry->f6; \
383 pes [5].color = index_color(5, num_nums, match_indices); \
384 printf ("%s ", #method + strlen ("binary_protocol_"));
386 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
387 BEGIN_PROTOCOL_ENTRY0 (method)
388 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
389 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
390 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
391 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
392 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
393 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
394 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
395 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
396 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
397 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
398 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
399 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
403 #define DEFAULT_PRINT() \
404 print_entry_content (pes_size, pes, color_output);
405 #define CUSTOM_PRINT(print) \
408 #define IS_ALWAYS_MATCH(_)
409 #define MATCH_INDEX(_)
410 #define IS_VTABLE_MATCH(_)
412 #define END_PROTOCOL_ENTRY \
416 #define END_PROTOCOL_ENTRY_HEAVY \
419 #include <mono/metadata/sgen-protocol-def.h>
431 #define TYPE_LONGLONG long long
432 #define TYPE_SIZE size_t
433 #define TYPE_POINTER gpointer
436 matches_interval (gpointer ptr, gpointer start, int size)
438 return ptr >= start && (char*)ptr < (char*)start + size;
441 /* Returns the index of the field where a match was found,
442 * BINARY_PROTOCOL_NO_MATCH for no match, or
443 * BINARY_PROTOCOL_MATCH for a match with no index.
446 match_index (gpointer ptr, int type, void *data)
448 switch (TYPE (type)) {
450 #define BEGIN_PROTOCOL_ENTRY0(method) \
451 case PROTOCOL_ID (method): {
452 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
453 case PROTOCOL_ID (method): { \
454 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
455 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
456 case PROTOCOL_ID (method): { \
457 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
458 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
459 case PROTOCOL_ID (method): { \
460 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
461 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
462 case PROTOCOL_ID (method): { \
463 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
464 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
465 case PROTOCOL_ID (method): { \
466 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
467 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
468 case PROTOCOL_ID (method): { \
469 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
471 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
472 BEGIN_PROTOCOL_ENTRY0 (method)
473 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
474 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
475 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
476 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
477 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
478 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
479 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
480 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
481 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
482 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
483 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
484 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
488 #define DEFAULT_PRINT()
489 #define CUSTOM_PRINT(_)
491 #define IS_ALWAYS_MATCH(_)
492 #define MATCH_INDEX(block) \
494 #define IS_VTABLE_MATCH(_)
496 #define END_PROTOCOL_ENTRY \
499 #define END_PROTOCOL_ENTRY_HEAVY \
502 #include <mono/metadata/sgen-protocol-def.h>
509 is_vtable_match (gpointer ptr, int type, void *data)
511 switch (TYPE (type)) {
513 #define BEGIN_PROTOCOL_ENTRY0(method) \
514 case PROTOCOL_ID (method): {
515 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
516 case PROTOCOL_ID (method): { \
517 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
518 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
519 case PROTOCOL_ID (method): { \
520 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
521 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
522 case PROTOCOL_ID (method): { \
523 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
524 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
525 case PROTOCOL_ID (method): { \
526 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
527 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
528 case PROTOCOL_ID (method): { \
529 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
530 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
531 case PROTOCOL_ID (method): { \
532 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
534 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
535 BEGIN_PROTOCOL_ENTRY0 (method)
536 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
537 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
538 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
539 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
540 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
541 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
542 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
543 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
544 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
545 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
546 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
547 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
551 #define DEFAULT_PRINT()
552 #define CUSTOM_PRINT(_)
554 #define IS_ALWAYS_MATCH(_)
555 #define MATCH_INDEX(block) \
557 #define IS_VTABLE_MATCH(_)
559 #define END_PROTOCOL_ENTRY \
562 #define END_PROTOCOL_ENTRY_HEAVY \
565 #include <mono/metadata/sgen-protocol-def.h>
577 main (int argc, char *argv[])
580 void *data = g_malloc0 (MAX_ENTRY_SIZE);
581 int num_args = argc - 1;
585 long nums [num_args];
586 long vtables [num_args];
587 gboolean dump_all = FALSE;
588 gboolean pause_times = FALSE;
589 gboolean pause_times_stopped = FALSE;
590 gboolean pause_times_concurrent = FALSE;
591 gboolean pause_times_finish = FALSE;
592 gboolean color_output = FALSE;
593 long long pause_times_ts = 0;
594 const char *input_path = NULL;
597 unsigned long long entry_index;
598 unsigned long long first_entry_to_consider = 0;
600 for (i = 0; i < num_args; ++i) {
601 char *arg = argv [i + 1];
602 char *next_arg = argv [i + 2];
603 if (!strcmp (arg, "--all")) {
605 } else if (!strcmp (arg, "--pause-times")) {
607 } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
608 vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
610 } else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
611 first_entry_to_consider = strtoull (next_arg, NULL, 10);
613 } else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
615 } else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
616 input_path = next_arg;
619 nums [num_nums++] = strtoul (arg, NULL, 16);
624 assert (!pause_times);
628 input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
629 init_stream (&stream, input_file);
631 while ((type = read_entry (&stream, data)) != SGEN_PROTOCOL_EOF) {
632 if (entry_index < first_entry_to_consider)
636 case PROTOCOL_ID (binary_protocol_world_stopping): {
637 PROTOCOL_STRUCT (binary_protocol_world_stopping) *entry = data;
638 assert (!pause_times_stopped);
639 pause_times_concurrent = FALSE;
640 pause_times_finish = FALSE;
641 pause_times_ts = entry->timestamp;
642 pause_times_stopped = TRUE;
645 case PROTOCOL_ID (binary_protocol_concurrent_finish):
646 pause_times_finish = TRUE;
647 case PROTOCOL_ID (binary_protocol_concurrent_start):
648 case PROTOCOL_ID (binary_protocol_concurrent_update):
649 pause_times_concurrent = TRUE;
651 case PROTOCOL_ID (binary_protocol_world_restarted): {
652 PROTOCOL_STRUCT (binary_protocol_world_restarted) *entry = data;
653 assert (pause_times_stopped);
654 printf ("pause-time %d %d %d %lld %lld\n",
656 pause_times_concurrent,
658 entry->timestamp - pause_times_ts,
660 pause_times_stopped = FALSE;
665 int match_indices [num_nums + 1];
666 gboolean match = is_always_match (type);
667 match_indices [num_nums] = num_nums == 0 ? match_index (NULL, type, data) : BINARY_PROTOCOL_NO_MATCH;
668 match = match_indices [num_nums] != BINARY_PROTOCOL_NO_MATCH;
669 for (i = 0; i < num_nums; ++i) {
670 match_indices [i] = match_index ((gpointer) nums [i], type, data);
671 match = match || match_indices [i] != BINARY_PROTOCOL_NO_MATCH;
674 for (i = 0; i < num_vtables; ++i) {
675 if (is_vtable_match ((gpointer) vtables [i], type, data)) {
681 if (match || dump_all)
682 printf ("%12lld ", entry_index);
684 printf (match ? "* " : " ");
685 if (match || dump_all)
686 print_entry (type, data, num_nums, match_indices, color_output);
691 close_stream (&stream);