From: Vlad Brezae Date: Thu, 5 May 2016 21:51:48 +0000 (+0300) Subject: [sgen] Split protocol entry grep from argument parsing X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=932d9b31158521dadcfee2f4cf502e8095cbc910;p=mono.git [sgen] Split protocol entry grep from argument parsing --- diff --git a/tools/sgen/Makefile.am b/tools/sgen/Makefile.am index 828090624c9..6d982d29548 100644 --- a/tools/sgen/Makefile.am +++ b/tools/sgen/Makefile.am @@ -3,7 +3,8 @@ bin_PROGRAMS = sgen-grep-binprot AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) sgen_grep_binprot_SOURCES = \ - sgen-grep-binprot.c \ + sgen-grep-binprot-main.c \ + sgen-grep-binprot.c \ sgen-entry-stream.c sgen_grep_binprot_LDADD = \ diff --git a/tools/sgen/sgen-grep-binprot-main.c b/tools/sgen/sgen-grep-binprot-main.c new file mode 100644 index 00000000000..7a4c363762d --- /dev/null +++ b/tools/sgen/sgen-grep-binprot-main.c @@ -0,0 +1,95 @@ +/* + * sgen-grep-binprot-main.c: Binary protocol entries reader + * + * Copyright (C) 2016 Xamarin Inc + * + * Licensed under the MIT license. See LICENSE file in the project root for full license information. + */ + +#include +#include +#include +#include +#include +#include +#include "sgen-entry-stream.h" +#include "sgen-grep-binprot.h" + +int +main (int argc, char *argv[]) +{ + int num_args = argc - 1; + int num_nums = 0; + int num_vtables = 0; + int i; + long nums [num_args]; + long vtables [num_args]; + gboolean dump_all = FALSE; + gboolean color_output = FALSE; + gboolean pause_times = FALSE; + const char *input_path = NULL; + int input_file; + EntryStream stream; + unsigned long long first_entry_to_consider = 0; + + for (i = 0; i < num_args; ++i) { + char *arg = argv [i + 1]; + char *next_arg = argv [i + 2]; + if (!strcmp (arg, "--all")) { + dump_all = TRUE; + } else if (!strcmp (arg, "--pause-times")) { + pause_times = TRUE; + } 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 #include #include @@ -8,6 +16,7 @@ #include #include #include "sgen-entry-stream.h" +#include "sgen-grep-binprot.h" #if SIZEOF_VOID_P == 4 typedef int32_t mword; @@ -534,85 +543,21 @@ is_vtable_match (mword ptr, int type, void *data) #undef TYPE_SIZE #undef TYPE_POINTER -int -main (int argc, char *argv[]) +void +sgen_binary_protocol_grep_entries (EntryStream *stream, int num_nums, long nums [], int num_vtables, long vtables [], + gboolean dump_all, gboolean pause_times, gboolean color_output, unsigned long long first_entry_to_consider) { int type; void *data = g_malloc0 (MAX_ENTRY_SIZE); - int num_args = argc - 1; - int num_nums = 0; - int num_vtables = 0; int i; - long nums [num_args]; - long vtables [num_args]; - gboolean dump_all = FALSE; - gboolean pause_times = FALSE; gboolean pause_times_stopped = FALSE; gboolean pause_times_concurrent = FALSE; gboolean pause_times_finish = FALSE; - gboolean color_output = FALSE; long long pause_times_ts = 0; - 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]; - char *next_arg = argv [i + 2]; - if (!strcmp (arg, "--all")) { - dump_all = TRUE; - } else if (!strcmp (arg, "--pause-times")) { - pause_times = TRUE; - } 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