From 117aa2510771ebfdf254dd5f4f88562a70afb59e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 20 Mar 2017 00:16:01 -0400 Subject: minidump_dump: add proper cli processing In preparation for adding more flexibility to this tool, add a proper parser for the command line flags. This uses the style as seen in other breakpad tools. BUG=chromium:598947 Change-Id: I95495e6ca7093be34d0d426f98a6c22880ff24a3 Reviewed-on: https://chromium-review.googlesource.com/457019 Reviewed-by: Mark Mentovai --- src/processor/minidump_dump.cc | 61 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) (limited to 'src/processor') diff --git a/src/processor/minidump_dump.cc b/src/processor/minidump_dump.cc index 343f0442..d6342cc4 100644 --- a/src/processor/minidump_dump.cc +++ b/src/processor/minidump_dump.cc @@ -34,6 +34,7 @@ #include #include +#include #include "common/scoped_ptr.h" #include "google_breakpad/processor/minidump.h" @@ -52,6 +53,13 @@ using google_breakpad::MinidumpSystemInfo; using google_breakpad::MinidumpMiscInfo; using google_breakpad::MinidumpBreakpadInfo; +struct Options { + Options() + : minidumpPath() {} + + string minidumpPath; +}; + static void DumpRawStream(Minidump *minidump, uint32_t stream_type, const char *stream_name, @@ -91,7 +99,7 @@ static void DumpRawStream(Minidump *minidump, printf("\n\n"); } -static bool PrintMinidumpDump(const char *minidump_file) { +static bool PrintMinidumpDump(const string& minidump_file) { Minidump minidump(minidump_file); if (!minidump.Read()) { BPLOG(ERROR) << "minidump.Read() failed"; @@ -199,15 +207,52 @@ static bool PrintMinidumpDump(const char *minidump_file) { return errors == 0; } -} // namespace +//============================================================================= +static void +Usage(int argc, const char *argv[], bool error) { + FILE *fp = error ? stderr : stdout; -int main(int argc, char **argv) { - BPLOG_INIT(&argc, &argv); + fprintf(fp, + "Usage: %s [options...] \n" + "Dump data in a minidump.\n" + "\n" + "Options:\n" + " should be a minidump.\n" + " -h:\t Usage\n", + argv[0]); +} + +//============================================================================= +static void +SetupOptions(int argc, const char *argv[], Options *options) { + int ch; + + while ((ch = getopt(argc, (char * const *)argv, "h")) != -1) { + switch (ch) { + case 'h': + Usage(argc, argv, false); + exit(0); - if (argc != 2) { - fprintf(stderr, "usage: %s \n", argv[0]); - return 1; + default: + Usage(argc, argv, true); + exit(1); + break; + } } - return PrintMinidumpDump(argv[1]) ? 0 : 1; + if ((argc - optind) != 1) { + fprintf(stderr, "%s: Missing minidump file\n", argv[0]); + exit(1); + } + + options->minidumpPath = argv[optind]; +} + +} // namespace + +int main(int argc, const char *argv[]) { + Options options; + BPLOG_INIT(&argc, &argv); + SetupOptions(argc, argv, &options); + return PrintMinidumpDump(options.minidumpPath) ? 0 : 1; } -- cgit v1.2.1