[mcs] Accept and ignore command line args supported by csc that we don't
[mono.git] / tools / sgen / sgen-grep-binprot.c
index 5335f01e71baf7031f5aa6321c08dbe8baff7b1d..49aa9506009e61411990764a262ad454eeeca8cf 100644 (file)
@@ -8,7 +8,7 @@
 #define SGEN_BINARY_PROTOCOL
 #define MONO_INTERNAL
 
-#include <mono/metadata/sgen-protocol.h>
+#include <mono/sgen/sgen-protocol.h>
 
 #define SGEN_PROTOCOL_EOF      255
 
@@ -110,8 +110,6 @@ read_entry (EntryStream *stream, void *data)
 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
        BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
 
-#define FLUSH()
-
 #define DEFAULT_PRINT()
 #define CUSTOM_PRINT(_)
 
@@ -120,9 +118,10 @@ read_entry (EntryStream *stream, void *data)
 #define IS_VTABLE_MATCH(_)
 
 #define END_PROTOCOL_ENTRY
+#define END_PROTOCOL_ENTRY_FLUSH
 #define END_PROTOCOL_ENTRY_HEAVY
 
-#include <mono/metadata/sgen-protocol-def.h>
+#include <mono/sgen/sgen-protocol-def.h>
 
        default: assert (0);
        }
@@ -169,8 +168,6 @@ is_always_match (int type)
 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
        BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
 
-#define FLUSH()
-
 #define DEFAULT_PRINT()
 #define CUSTOM_PRINT(_)
 
@@ -180,9 +177,10 @@ is_always_match (int type)
 #define IS_VTABLE_MATCH(_)
 
 #define END_PROTOCOL_ENTRY
+#define END_PROTOCOL_ENTRY_FLUSH
 #define END_PROTOCOL_ENTRY_HEAVY
 
-#include <mono/metadata/sgen-protocol-def.h>
+#include <mono/sgen/sgen-protocol-def.h>
 
        default: assert (0);
        }
@@ -207,6 +205,7 @@ typedef struct {
 #define TYPE_LONGLONG 1
 #define TYPE_SIZE 2
 #define TYPE_POINTER 3
+#define TYPE_BOOL 4
 
 static void
 print_entry_content (int entries_size, PrintEntry *entries, gboolean color_output)
@@ -230,6 +229,9 @@ print_entry_content (int entries_size, PrintEntry *entries, gboolean color_outpu
                case TYPE_POINTER:
                        printf ("%p", *(gpointer*) entries [i].data);
                        break;
+               case TYPE_BOOL:
+                       printf ("%s", *(gboolean*) entries [i].data ? "true" : "false");
+                       break;
                default:
                        assert (0);
                }
@@ -398,8 +400,6 @@ print_entry (int type, void *data, int num_nums, int *match_indices, gboolean co
 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
        BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
 
-#define FLUSH()
-
 #define DEFAULT_PRINT() \
        print_entry_content (pes_size, pes, color_output);
 #define CUSTOM_PRINT(print) \
@@ -413,10 +413,12 @@ print_entry (int type, void *data, int num_nums, int *match_indices, gboolean co
                printf ("\n"); \
                break; \
        }
+#define END_PROTOCOL_ENTRY_FLUSH \
+       END_PROTOCOL_ENTRY
 #define END_PROTOCOL_ENTRY_HEAVY \
        END_PROTOCOL_ENTRY
 
-#include <mono/metadata/sgen-protocol-def.h>
+#include <mono/sgen/sgen-protocol-def.h>
 
        default: assert (0);
        }
@@ -483,8 +485,6 @@ match_index (gpointer ptr, int type, void *data)
 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
        BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
 
-#define FLUSH()
-
 #define DEFAULT_PRINT()
 #define CUSTOM_PRINT(_)
 
@@ -496,10 +496,12 @@ match_index (gpointer ptr, int type, void *data)
 #define END_PROTOCOL_ENTRY \
                break; \
        }
+#define END_PROTOCOL_ENTRY_FLUSH \
+       END_PROTOCOL_ENTRY
 #define END_PROTOCOL_ENTRY_HEAVY \
        END_PROTOCOL_ENTRY
 
-#include <mono/metadata/sgen-protocol-def.h>
+#include <mono/sgen/sgen-protocol-def.h>
 
        default: assert (0);
        }
@@ -546,8 +548,6 @@ is_vtable_match (gpointer ptr, int type, void *data)
 #define BEGIN_PROTOCOL_ENTRY_HEAVY6(method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6) \
        BEGIN_PROTOCOL_ENTRY6 (method,t1,f1,t2,f2,t3,f3,t4,f4,t5,f5,t6,f6)
 
-#define FLUSH()
-
 #define DEFAULT_PRINT()
 #define CUSTOM_PRINT(_)
 
@@ -559,10 +559,12 @@ is_vtable_match (gpointer ptr, int type, void *data)
 #define END_PROTOCOL_ENTRY \
                break; \
        }
+#define END_PROTOCOL_ENTRY_FLUSH \
+       END_PROTOCOL_ENTRY
 #define END_PROTOCOL_ENTRY_HEAVY \
        END_PROTOCOL_ENTRY
 
-#include <mono/metadata/sgen-protocol-def.h>
+#include <mono/sgen/sgen-protocol-def.h>
 
        default: assert (0);
        }
@@ -594,6 +596,8 @@ main (int argc, char *argv[])
        const char *input_path = NULL;
        int input_file;
        EntryStream stream;
+       unsigned long long entry_index;
+       unsigned long long first_entry_to_consider = 0;
 
        for (i = 0; i < num_args; ++i) {
                char *arg = argv [i + 1];
@@ -605,11 +609,37 @@ main (int argc, char *argv[])
                } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
                        vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
                        ++i;
+               } else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
+                       first_entry_to_consider = strtoull (next_arg, NULL, 10);
+                       ++i;
                } else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
                        color_output = TRUE;
                } else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
                        input_path = next_arg;
                        ++i;
+               } else if (!strcmp (arg, "--help")) {
+                       printf (
+                               "\n"
+                               "Usage:\n"
+                               "\n"
+                               "\tsgen-grep-binprot [options] [pointer...]\n"
+                               "\n"
+                               "Examples:\n"
+                               "\n"
+                               "\tsgen-grep-binprot --all </tmp/binprot\n"
+                               "\tsgen-grep-binprot --input /tmp/binprot --color 0xdeadbeef\n"
+                               "\n"
+                               "Options:\n"
+                               "\n"
+                               "\t--all                    Print all entries.\n"
+                               "\t--color, -c              Highlight matches in color.\n"
+                               "\t--help                   You're looking at it.\n"
+                               "\t--input FILE, -i FILE    Read input from FILE instead of standard input.\n"
+                               "\t--pause-times            Print GC pause times.\n"
+                               "\t--start-at N, -s N       Begin filtering at the Nth entry.\n"
+                               "\t--vtable PTR, -v PTR     Search for vtable pointer PTR.\n"
+                               "\n");
+                       return 0;
                } else {
                        nums [num_nums++] = strtoul (arg, NULL, 16);
                }
@@ -622,7 +652,10 @@ main (int argc, char *argv[])
 
        input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
        init_stream (&stream, input_file);
+       entry_index = 0;
        while ((type = read_entry (&stream, data)) != SGEN_PROTOCOL_EOF) {
+               if (entry_index < first_entry_to_consider)
+                       goto next_entry;
                if (pause_times) {
                        switch (type) {
                        case PROTOCOL_ID (binary_protocol_world_stopping): {
@@ -670,11 +703,15 @@ main (int argc, char *argv[])
                                        }
                                }
                        }
+                       if (match || dump_all)
+                               printf ("%12lld ", entry_index);
                        if (dump_all)
                                printf (match ? "* " : "  ");
                        if (match || dump_all)
                                print_entry (type, data, num_nums, match_indices, color_output);
                }
+       next_entry:
+               ++entry_index;
        }
        close_stream (&stream);
        if (input_path)