aboutsummaryrefslogtreecommitdiff
path: root/src/processor
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2017-03-20 00:16:01 -0400
committerMike Frysinger <vapier@chromium.org>2017-03-24 16:21:48 +0000
commit117aa2510771ebfdf254dd5f4f88562a70afb59e (patch)
tree503b7dc43030425141ee377ba4eb453c5dcf98dc /src/processor
parentadd -Wunused-local-typedefs to the set of warning flags (diff)
downloadbreakpad-117aa2510771ebfdf254dd5f4f88562a70afb59e.tar.xz
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 <mark@chromium.org>
Diffstat (limited to 'src/processor')
-rw-r--r--src/processor/minidump_dump.cc61
1 files changed, 53 insertions, 8 deletions
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 <stdio.h>
#include <string.h>
+#include <unistd.h>
#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...] <minidump>\n"
+ "Dump data in a minidump.\n"
+ "\n"
+ "Options:\n"
+ " <minidump> 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 <file>\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;
}