2 * sgen-grep-binprot-main.c: 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.
15 #include "sgen-entry-stream.h"
16 #include "sgen-grep-binprot.h"
18 GrepEntriesFunction grepers [] = {
19 sgen_binary_protocol_grep_entriesp,
20 sgen_binary_protocol_grep_entries
24 main (int argc, char *argv[])
26 int num_args = argc - 1;
31 long vtables [num_args];
32 gboolean dump_all = FALSE;
33 gboolean color_output = FALSE;
34 gboolean pause_times = FALSE;
35 const char *input_path = NULL;
38 unsigned long long first_entry_to_consider = 0;
40 for (i = 0; i < num_args; ++i) {
41 char *arg = argv [i + 1];
42 char *next_arg = argv [i + 2];
43 if (!strcmp (arg, "--all")) {
45 } else if (!strcmp (arg, "--pause-times")) {
47 } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
48 vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
50 } else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
51 first_entry_to_consider = strtoull (next_arg, NULL, 10);
53 } else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
55 } else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
56 input_path = next_arg;
58 } else if (!strcmp (arg, "--help")) {
63 "\tsgen-grep-binprot [options] [pointer...]\n"
67 "\tsgen-grep-binprot --all </tmp/binprot\n"
68 "\tsgen-grep-binprot --input /tmp/binprot --color 0xdeadbeef\n"
72 "\t--all Print all entries.\n"
73 "\t--color, -c Highlight matches in color.\n"
74 "\t--help You're looking at it.\n"
75 "\t--input FILE, -i FILE Read input from FILE instead of standard input.\n"
76 "\t--pause-times Print GC pause times.\n"
77 "\t--start-at N, -s N Begin filtering at the Nth entry.\n"
78 "\t--vtable PTR, -v PTR Search for vtable pointer PTR.\n"
82 nums [num_nums++] = strtoul (arg, NULL, 16);
87 assert (!pause_times);
91 input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
92 init_stream (&stream, input_file);
93 for (i = 0; i < sizeof (grepers) / sizeof (GrepEntriesFunction); i++) {
94 if (grepers [i] (&stream, num_nums, nums, num_vtables, vtables, dump_all,
95 pause_times, color_output, first_entry_to_consider)) {
99 reset_stream (&stream);
101 close_stream (&stream);