8 #define SGEN_BINARY_PROTOCOL
11 #include <mono/sgen/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)
113 #define DEFAULT_PRINT()
114 #define CUSTOM_PRINT(_)
116 #define IS_ALWAYS_MATCH(_)
117 #define MATCH_INDEX(_)
118 #define IS_VTABLE_MATCH(_)
120 #define END_PROTOCOL_ENTRY
121 #define END_PROTOCOL_ENTRY_FLUSH
122 #define END_PROTOCOL_ENTRY_HEAVY
124 #include <mono/sgen/sgen-protocol-def.h>
130 size_t size_read = read_stream (stream, data, size);
131 g_assert (size_read == size);
138 is_always_match (int type)
140 switch (TYPE (type)) {
141 #define BEGIN_PROTOCOL_ENTRY0(method) \
142 case PROTOCOL_ID(method):
143 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
144 case PROTOCOL_ID(method):
145 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
146 case PROTOCOL_ID(method):
147 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
148 case PROTOCOL_ID(method):
149 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
150 case PROTOCOL_ID(method):
151 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
152 case PROTOCOL_ID(method):
153 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
154 case PROTOCOL_ID(method):
156 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
157 BEGIN_PROTOCOL_ENTRY0 (method)
158 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
159 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
160 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
161 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
162 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
163 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
164 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
165 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
166 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
167 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
168 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
169 BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
171 #define DEFAULT_PRINT()
172 #define CUSTOM_PRINT(_)
174 #define IS_ALWAYS_MATCH(is_always_match) \
175 return is_always_match;
176 #define MATCH_INDEX(_)
177 #define IS_VTABLE_MATCH(_)
179 #define END_PROTOCOL_ENTRY
180 #define END_PROTOCOL_ENTRY_FLUSH
181 #define END_PROTOCOL_ENTRY_HEAVY
183 #include <mono/sgen/sgen-protocol-def.h>
189 #define WORKER_PREFIX(t) (WORKER ((t)) ? "w" : " ")
191 enum { NO_COLOR = -1 };
197 /* The index of the ANSI color with which to highlight
198 * this entry, or NO_COLOR for no highlighting.
205 #define TYPE_LONGLONG 1
207 #define TYPE_POINTER 3
211 print_entry_content (int entries_size, PrintEntry *entries, gboolean color_output)
214 for (i = 0; i < entries_size; ++i) {
215 printf ("%s%s ", i == 0 ? "" : " ", entries [i].name);
216 if (color_output && entries [i].color != NO_COLOR)
217 /* Set foreground color, excluding black & white. */
218 printf ("\x1B[%dm", 31 + (entries [i].color % 6));
219 switch (entries [i].type) {
221 printf ("%d", *(int*) entries [i].data);
224 printf ("%lld", *(long long*) entries [i].data);
227 printf ("%lu", *(size_t*) entries [i].data);
230 printf ("%p", *(gpointer*) entries [i].data);
233 printf ("%s", *(gboolean*) entries [i].data ? "true" : "false");
238 if (color_output && entries [i].color != NO_COLOR)
239 /* Reset foreground color to default. */
245 index_color (int index, int num_nums, int *match_indices)
248 for (result = 0; result < num_nums + 1; ++result)
249 if (index == match_indices [result])
255 print_entry (int type, void *data, int num_nums, int *match_indices, gboolean color_output)
257 const char *always_prefix = is_always_match (type) ? " " : "";
258 printf ("%s%s ", WORKER_PREFIX (type), always_prefix);
260 switch (TYPE (type)) {
262 #define BEGIN_PROTOCOL_ENTRY0(method) \
263 case PROTOCOL_ID(method): { \
264 const int pes_size G_GNUC_UNUSED = 0; \
265 PrintEntry pes [1] G_GNUC_UNUSED; \
266 printf ("%s", #method + strlen ("binary_protocol_"));
267 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
268 case PROTOCOL_ID(method): { \
269 PROTOCOL_STRUCT (method) *entry = data; \
270 const int pes_size G_GNUC_UNUSED = 1; \
271 PrintEntry pes [1] G_GNUC_UNUSED; \
273 pes [0].name = #f1; \
274 pes [0].data = &entry->f1; \
275 pes [0].color = index_color(0, num_nums, match_indices); \
276 printf ("%s ", #method + strlen ("binary_protocol_"));
277 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
278 case PROTOCOL_ID(method): { \
279 PROTOCOL_STRUCT (method) *entry = data; \
280 const int pes_size G_GNUC_UNUSED = 2; \
281 PrintEntry pes [2] G_GNUC_UNUSED; \
283 pes [0].name = #f1; \
284 pes [0].data = &entry->f1; \
285 pes [0].color = index_color(0, num_nums, match_indices); \
287 pes [1].name = #f2; \
288 pes [1].data = &entry->f2; \
289 pes [1].color = index_color(1, num_nums, match_indices); \
290 printf ("%s ", #method + strlen ("binary_protocol_"));
291 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
292 case PROTOCOL_ID(method): { \
293 PROTOCOL_STRUCT (method) *entry = data; \
294 const int pes_size G_GNUC_UNUSED = 3; \
295 PrintEntry pes [3] G_GNUC_UNUSED; \
297 pes [0].name = #f1; \
298 pes [0].data = &entry->f1; \
299 pes [0].color = index_color(0, num_nums, match_indices); \
301 pes [1].name = #f2; \
302 pes [1].data = &entry->f2; \
303 pes [1].color = index_color(1, num_nums, match_indices); \
305 pes [2].name = #f3; \
306 pes [2].data = &entry->f3; \
307 pes [2].color = index_color(2, num_nums, match_indices); \
308 printf ("%s ", #method + strlen ("binary_protocol_"));
309 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
310 case PROTOCOL_ID(method): { \
311 PROTOCOL_STRUCT (method) *entry = data; \
312 const int pes_size G_GNUC_UNUSED = 4; \
313 PrintEntry pes [4] G_GNUC_UNUSED; \
315 pes [0].name = #f1; \
316 pes [0].data = &entry->f1; \
317 pes [0].color = index_color(0, num_nums, match_indices); \
319 pes [1].name = #f2; \
320 pes [1].data = &entry->f2; \
321 pes [1].color = index_color(1, num_nums, match_indices); \
323 pes [2].name = #f3; \
324 pes [2].data = &entry->f3; \
325 pes [2].color = index_color(2, num_nums, match_indices); \
327 pes [3].name = #f4; \
328 pes [3].data = &entry->f4; \
329 pes [3].color = index_color(3, num_nums, match_indices); \
330 printf ("%s ", #method + strlen ("binary_protocol_"));
331 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
332 case PROTOCOL_ID(method): { \
333 PROTOCOL_STRUCT (method) *entry = data; \
334 const int pes_size G_GNUC_UNUSED = 5; \
335 PrintEntry pes [5] G_GNUC_UNUSED; \
337 pes [0].name = #f1; \
338 pes [0].data = &entry->f1; \
339 pes [0].color = index_color(0, num_nums, match_indices); \
341 pes [1].name = #f2; \
342 pes [1].data = &entry->f2; \
343 pes [1].color = index_color(1, num_nums, match_indices); \
345 pes [2].name = #f3; \
346 pes [2].data = &entry->f3; \
347 pes [2].color = index_color(2, num_nums, match_indices); \
349 pes [3].name = #f4; \
350 pes [3].data = &entry->f4; \
351 pes [3].color = index_color(3, num_nums, match_indices); \
353 pes [4].name = #f5; \
354 pes [4].data = &entry->f5; \
355 pes [4].color = index_color(4, num_nums, match_indices); \
356 printf ("%s ", #method + strlen ("binary_protocol_"));
357 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
358 case PROTOCOL_ID(method): { \
359 PROTOCOL_STRUCT (method) *entry = data; \
360 const int pes_size G_GNUC_UNUSED = 6; \
361 PrintEntry pes [6] G_GNUC_UNUSED; \
363 pes [0].name = #f1; \
364 pes [0].data = &entry->f1; \
365 pes [0].color = index_color(0, num_nums, match_indices); \
367 pes [1].name = #f2; \
368 pes [1].data = &entry->f2; \
369 pes [1].color = index_color(1, num_nums, match_indices); \
371 pes [2].name = #f3; \
372 pes [2].data = &entry->f3; \
373 pes [2].color = index_color(2, num_nums, match_indices); \
375 pes [3].name = #f4; \
376 pes [3].data = &entry->f4; \
377 pes [3].color = index_color(3, num_nums, match_indices); \
379 pes [4].name = #f5; \
380 pes [4].data = &entry->f5; \
381 pes [4].color = index_color(4, num_nums, match_indices); \
383 pes [5].name = #f6; \
384 pes [5].data = &entry->f6; \
385 pes [5].color = index_color(5, num_nums, match_indices); \
386 printf ("%s ", #method + strlen ("binary_protocol_"));
388 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
389 BEGIN_PROTOCOL_ENTRY0 (method)
390 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
391 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
392 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
393 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
394 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
395 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
396 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
397 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
398 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
399 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
400 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
401 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_FLUSH \
418 #define END_PROTOCOL_ENTRY_HEAVY \
421 #include <mono/sgen/sgen-protocol-def.h>
433 #define TYPE_LONGLONG long long
434 #define TYPE_SIZE size_t
435 #define TYPE_POINTER gpointer
438 matches_interval (gpointer ptr, gpointer start, int size)
440 return ptr >= start && (char*)ptr < (char*)start + size;
443 /* Returns the index of the field where a match was found,
444 * BINARY_PROTOCOL_NO_MATCH for no match, or
445 * BINARY_PROTOCOL_MATCH for a match with no index.
448 match_index (gpointer ptr, int type, void *data)
450 switch (TYPE (type)) {
452 #define BEGIN_PROTOCOL_ENTRY0(method) \
453 case PROTOCOL_ID (method): {
454 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
455 case PROTOCOL_ID (method): { \
456 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
457 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
458 case PROTOCOL_ID (method): { \
459 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
460 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
461 case PROTOCOL_ID (method): { \
462 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
463 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
464 case PROTOCOL_ID (method): { \
465 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
466 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
467 case PROTOCOL_ID (method): { \
468 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
469 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
470 case PROTOCOL_ID (method): { \
471 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
473 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
474 BEGIN_PROTOCOL_ENTRY0 (method)
475 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
476 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
477 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
478 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
479 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
480 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
481 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
482 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
483 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
484 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
485 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
486 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_FLUSH \
501 #define END_PROTOCOL_ENTRY_HEAVY \
504 #include <mono/sgen/sgen-protocol-def.h>
511 is_vtable_match (gpointer ptr, int type, void *data)
513 switch (TYPE (type)) {
515 #define BEGIN_PROTOCOL_ENTRY0(method) \
516 case PROTOCOL_ID (method): {
517 #define BEGIN_PROTOCOL_ENTRY1(method,t1,f1) \
518 case PROTOCOL_ID (method): { \
519 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
520 #define BEGIN_PROTOCOL_ENTRY2(method,t1,f1,t2,f2) \
521 case PROTOCOL_ID (method): { \
522 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
523 #define BEGIN_PROTOCOL_ENTRY3(method,t1,f1,t2,f2,t3,f3) \
524 case PROTOCOL_ID (method): { \
525 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
526 #define BEGIN_PROTOCOL_ENTRY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
527 case PROTOCOL_ID (method): { \
528 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
529 #define BEGIN_PROTOCOL_ENTRY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
530 case PROTOCOL_ID (method): { \
531 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
532 #define BEGIN_PROTOCOL_ENTRY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
533 case PROTOCOL_ID (method): { \
534 PROTOCOL_STRUCT (method) *entry G_GNUC_UNUSED = data;
536 #define BEGIN_PROTOCOL_ENTRY_HEAVY0(method) \
537 BEGIN_PROTOCOL_ENTRY0 (method)
538 #define BEGIN_PROTOCOL_ENTRY_HEAVY1(method,t1,f1) \
539 BEGIN_PROTOCOL_ENTRY1 (method,t1,f1)
540 #define BEGIN_PROTOCOL_ENTRY_HEAVY2(method,t1,f1,t2,f2) \
541 BEGIN_PROTOCOL_ENTRY2 (method,t1,f1,t2,f2)
542 #define BEGIN_PROTOCOL_ENTRY_HEAVY3(method,t1,f1,t2,f2,t3,f3) \
543 BEGIN_PROTOCOL_ENTRY3 (method,t1,f1,t2,f2,t3,f3)
544 #define BEGIN_PROTOCOL_ENTRY_HEAVY4(method,t1,f1,t2,f2,t3,f3,t4,f4) \
545 BEGIN_PROTOCOL_ENTRY4 (method,t1,f1,t2,f2,t3,f3,t4,f4)
546 #define BEGIN_PROTOCOL_ENTRY_HEAVY5(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5) \
547 BEGIN_PROTOCOL_ENTRY5 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5)
548 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
549 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_FLUSH \
564 #define END_PROTOCOL_ENTRY_HEAVY \
567 #include <mono/sgen/sgen-protocol-def.h>
579 main (int argc, char *argv[])
582 void *data = g_malloc0 (MAX_ENTRY_SIZE);
583 int num_args = argc - 1;
587 long nums [num_args];
588 long vtables [num_args];
589 gboolean dump_all = FALSE;
590 gboolean pause_times = FALSE;
591 gboolean pause_times_stopped = FALSE;
592 gboolean pause_times_concurrent = FALSE;
593 gboolean pause_times_finish = FALSE;
594 gboolean color_output = FALSE;
595 long long pause_times_ts = 0;
596 const char *input_path = NULL;
599 unsigned long long entry_index;
600 unsigned long long first_entry_to_consider = 0;
602 for (i = 0; i < num_args; ++i) {
603 char *arg = argv [i + 1];
604 char *next_arg = argv [i + 2];
605 if (!strcmp (arg, "--all")) {
607 } else if (!strcmp (arg, "--pause-times")) {
609 } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
610 vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
612 } else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
613 first_entry_to_consider = strtoull (next_arg, NULL, 10);
615 } else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
617 } else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
618 input_path = next_arg;
620 } else if (!strcmp (arg, "--help")) {
625 "\tsgen-grep-binprot [options] [pointer...]\n"
629 "\tsgen-grep-binprot --all </tmp/binprot\n"
630 "\tsgen-grep-binprot --input /tmp/binprot --color 0xdeadbeef\n"
634 "\t--all Print all entries.\n"
635 "\t--color, -c Highlight matches in color.\n"
636 "\t--help You're looking at it.\n"
637 "\t--input FILE, -i FILE Read input from FILE instead of standard input.\n"
638 "\t--pause-times Print GC pause times.\n"
639 "\t--start-at N, -s N Begin filtering at the Nth entry.\n"
640 "\t--vtable PTR, -v PTR Search for vtable pointer PTR.\n"
644 nums [num_nums++] = strtoul (arg, NULL, 16);
649 assert (!pause_times);
653 input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
654 init_stream (&stream, input_file);
656 while ((type = read_entry (&stream, data)) != SGEN_PROTOCOL_EOF) {
657 if (entry_index < first_entry_to_consider)
661 case PROTOCOL_ID (binary_protocol_world_stopping): {
662 PROTOCOL_STRUCT (binary_protocol_world_stopping) *entry = data;
663 assert (!pause_times_stopped);
664 pause_times_concurrent = FALSE;
665 pause_times_finish = FALSE;
666 pause_times_ts = entry->timestamp;
667 pause_times_stopped = TRUE;
670 case PROTOCOL_ID (binary_protocol_concurrent_finish):
671 pause_times_finish = TRUE;
672 case PROTOCOL_ID (binary_protocol_concurrent_start):
673 case PROTOCOL_ID (binary_protocol_concurrent_update):
674 pause_times_concurrent = TRUE;
676 case PROTOCOL_ID (binary_protocol_world_restarted): {
677 PROTOCOL_STRUCT (binary_protocol_world_restarted) *entry = data;
678 assert (pause_times_stopped);
679 printf ("pause-time %d %d %d %lld %lld\n",
681 pause_times_concurrent,
683 entry->timestamp - pause_times_ts,
685 pause_times_stopped = FALSE;
690 int match_indices [num_nums + 1];
691 gboolean match = is_always_match (type);
692 match_indices [num_nums] = num_nums == 0 ? match_index (NULL, type, data) : BINARY_PROTOCOL_NO_MATCH;
693 match = match_indices [num_nums] != BINARY_PROTOCOL_NO_MATCH;
694 for (i = 0; i < num_nums; ++i) {
695 match_indices [i] = match_index ((gpointer) nums [i], type, data);
696 match = match || match_indices [i] != BINARY_PROTOCOL_NO_MATCH;
699 for (i = 0; i < num_vtables; ++i) {
700 if (is_vtable_match ((gpointer) vtables [i], type, data)) {
706 if (match || dump_all)
707 printf ("%12lld ", entry_index);
709 printf (match ? "* " : " ");
710 if (match || dump_all)
711 print_entry (type, data, num_nums, match_indices, color_output);
716 close_stream (&stream);