mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2024-11-24 08:45:37 +01:00
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>
This commit is contained in:
parent
b37547bc70
commit
117aa25107
@ -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]);
|
||||
}
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s <file>\n", argv[0]);
|
||||
return 1;
|
||||
//=============================================================================
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user