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 /* FIXME Add grepers for specific endianness */
19 GrepEntriesFunction grepers [] = {
20 sgen_binary_protocol_grep_entries32p, /* We have header, structures are packed, 32 bit word */
21 sgen_binary_protocol_grep_entries64p, /* We have header, structures are packed, 64 bit word */
22 sgen_binary_protocol_grep_entries /* No header, uses default word size and structure layout */
26 main (int argc, char *argv[])
28 int num_args = argc - 1;
33 long vtables [num_args];
34 gboolean dump_all = FALSE;
35 gboolean color_output = FALSE;
36 gboolean pause_times = FALSE;
37 const char *input_path = NULL;
40 unsigned long long first_entry_to_consider = 0;
42 for (i = 0; i < num_args; ++i) {
43 char *arg = argv [i + 1];
44 char *next_arg = argv [i + 2];
45 if (!strcmp (arg, "--all")) {
47 } else if (!strcmp (arg, "--pause-times")) {
49 } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
50 vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
52 } else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
53 first_entry_to_consider = strtoull (next_arg, NULL, 10);
55 } else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
57 } else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
58 input_path = next_arg;
60 } else if (!strcmp (arg, "--help")) {
65 "\tsgen-grep-binprot [options] [pointer...]\n"
69 "\tsgen-grep-binprot --all </tmp/binprot\n"
70 "\tsgen-grep-binprot --input /tmp/binprot --color 0xdeadbeef\n"
74 "\t--all Print all entries.\n"
75 "\t--color, -c Highlight matches in color.\n"
76 "\t--help You're looking at it.\n"
77 "\t--input FILE, -i FILE Read input from FILE instead of standard input.\n"
78 "\t--pause-times Print GC pause times.\n"
79 "\t--start-at N, -s N Begin filtering at the Nth entry.\n"
80 "\t--vtable PTR, -v PTR Search for vtable pointer PTR.\n"
84 nums [num_nums++] = strtoul (arg, NULL, 16);
89 assert (!pause_times);
93 input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
94 init_stream (&stream, input_file);
95 for (i = 0; i < sizeof (grepers) / sizeof (GrepEntriesFunction); i++) {
96 if (grepers [i] (&stream, num_nums, nums, num_vtables, vtables, dump_all,
97 pause_times, color_output, first_entry_to_consider)) {
101 reset_stream (&stream);
103 close_stream (&stream);