Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Unified Diff: tools/crashpad_database_util.cc

Issue 1119783005: win: get tools/crashpad_database_util mostly working (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: roll Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/crashpad_database_util.cc
diff --git a/tools/crashpad_database_util.cc b/tools/crashpad_database_util.cc
index cd5a2195bd5b2146a1abb28ee0b3dabfea8c329b..12b37d65853831b1e4fe5129c6573847968c4185 100644
--- a/tools/crashpad_database_util.cc
+++ b/tools/crashpad_database_util.cc
@@ -14,7 +14,6 @@
#include <errno.h>
#include <getopt.h>
-#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -25,10 +24,13 @@
#include <vector>
#include "base/basictypes.h"
-#include "base/logging.h"
#include "base/files/file_path.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/numerics/safe_conversions.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "build/build_config.h"
#include "client/crash_report_database.h"
#include "client/settings.h"
#include "tools/tool_support.h"
@@ -36,12 +38,26 @@
#include "util/file/file_reader.h"
#include "util/misc/uuid.h"
+#if defined(OS_MACOSX)
+#include <libgen.h>
Mark Mentovai 2015/05/05 22:25:27 Remove this. It was only here for basename().
scottmg 2015/05/05 23:03:37 Done.
+#endif // OS_MACOSX
+
+#if defined(OS_POSIX)
+base::FilePath::StringType UTF8ToFilePathStringType(const char* path) {
+ return path;
+}
+#elif defined(OS_WIN)
+base::FilePath::StringType UTF8ToFilePathStringType(const char* path) {
+ return base::UTF8ToUTF16(path);
+}
+#endif
+
namespace crashpad {
namespace {
-void Usage(const std::string& me) {
+void Usage(const base::FilePath& me) {
fprintf(stderr,
-"Usage: %s [OPTION]... PID\n"
+"Usage: %" PRFilePath " [OPTION]... PID\n"
"Operate on Crashpad crash report databases.\n"
"\n"
" -d, --database=PATH operate on the crash report database at PATH\n"
@@ -60,7 +76,7 @@ void Usage(const std::string& me) {
" --utc show and set UTC times instead of local\n"
" --help display this help and exit\n"
" --version output version information and exit\n",
- me.c_str());
+ me.value().c_str());
ToolSupport::UsageTail(me);
}
@@ -104,14 +120,14 @@ bool StringToBool(const char* string, bool* boolean) {
};
for (size_t index = 0; index < arraysize(kFalseWords); ++index) {
- if (strcasecmp(string, kFalseWords[index]) == 0) {
+ if (base::strcasecmp(string, kFalseWords[index]) == 0) {
*boolean = false;
return true;
}
}
for (size_t index = 0; index < arraysize(kTrueWords); ++index) {
- if (strcasecmp(string, kTrueWords[index]) == 0) {
+ if (base::strcasecmp(string, kTrueWords[index]) == 0) {
*boolean = true;
return true;
}
@@ -133,7 +149,7 @@ std::string BoolToString(bool boolean) {
// when true, causes |string| to be interpreted as a UTC time rather than a
// local time when the time zone is ambiguous.
bool StringToTime(const char* string, time_t* time, bool utc) {
- if (strcasecmp(string, "never") == 0) {
+ if (base::strcasecmp(string, "never") == 0) {
*time = 0;
return true;
}
@@ -153,7 +169,7 @@ bool StringToTime(const char* string, time_t* time, bool utc) {
if (utc) {
*time = timegm(&time_tm);
} else {
- *time = timelocal(&time_tm);
+ *time = mktime(&time_tm);
}
return true;
@@ -172,7 +188,7 @@ bool StringToTime(const char* string, time_t* time, bool utc) {
return false;
}
-// Converst |time_tt| to a string, and returns it. |utc| determines whether the
+// Converts |time_tt| to a string, and returns it. |utc| determines whether the
// converted time will reference local time or UTC. If |time_tt| is 0, the
// string "never" will be returned as a special case.
std::string TimeToString(time_t time_tt, bool utc) {
@@ -182,9 +198,17 @@ std::string TimeToString(time_t time_tt, bool utc) {
tm time_tm;
if (utc) {
+#if defined(OS_POSIX)
gmtime_r(&time_tt, &time_tm);
+#elif defined(OS_WIN)
+ gmtime_s(&time_tm, &time_tt);
Mark Mentovai 2015/05/05 22:19:49 gmtime_r() and localtime_r() can wrap gmtime_s() a
scottmg 2015/05/05 23:03:37 Done.
+#endif // OS_POSIX
} else {
+#if defined(OS_POSIX)
localtime_r(&time_tt, &time_tm);
+#elif defined(OS_WIN)
+ localtime_s(&time_tm, &time_tt);
+#endif // OS_POSIX
}
char string[64];
@@ -203,7 +227,9 @@ void ShowReport(const CrashReportDatabase::Report& report,
bool utc) {
std::string spaces(space_count, ' ');
- printf("%sPath: %s\n", spaces.c_str(), report.file_path.value().c_str());
+ printf("%sPath: %" PRFilePath "\n",
+ spaces.c_str(),
+ report.file_path.value().c_str());
if (!report.id.empty()) {
printf("%sRemote ID: %s\n", spaces.c_str(), report.id.c_str());
}
@@ -239,7 +265,8 @@ void ShowReports(const std::vector<CrashReportDatabase::Report>& reports,
}
int DatabaseUtilMain(int argc, char* argv[]) {
- const std::string me(basename(argv[0]));
+ const base::FilePath me(
+ base::FilePath(UTF8ToFilePathStringType(argv[0])).BaseName());
enum OptionFlags {
// “Short” (single-character) options.
@@ -297,7 +324,8 @@ int DatabaseUtilMain(int argc, char* argv[]) {
Options options = {};
int opt;
- while ((opt = getopt_long(argc, argv, "d:", long_options, nullptr)) != -1) {
+ while ((opt = getopt_long(
Mark Mentovai 2015/05/05 22:19:49 This fit on one line before and you haven’t change
scottmg 2015/05/05 23:03:37 Oops, missed that in my conversions back and forth
+ argc, argv, "d:", long_options, nullptr)) != -1) {
switch (opt) {
case kOptionDatabase: {
options.database = optarg;
@@ -349,7 +377,8 @@ int DatabaseUtilMain(int argc, char* argv[]) {
break;
}
case kOptionNewReport: {
- options.new_report_paths.push_back(base::FilePath(optarg));
+ options.new_report_paths.push_back(
+ base::FilePath(UTF8ToFilePathStringType(optarg)));
break;
}
case kOptionUTC: {
@@ -408,8 +437,8 @@ int DatabaseUtilMain(int argc, char* argv[]) {
return EXIT_FAILURE;
}
- scoped_ptr<CrashReportDatabase> database(
- CrashReportDatabase::Initialize(base::FilePath(options.database)));
+ scoped_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize(
+ base::FilePath(UTF8ToFilePathStringType(options.database))));
if (!database) {
return EXIT_FAILURE;
}
@@ -453,7 +482,7 @@ int DatabaseUtilMain(int argc, char* argv[]) {
printf("%s%s (%ld)\n",
prefix,
TimeToString(last_upload_attempt_time, options.utc).c_str(),
- implicit_cast<long>(last_upload_attempt_time));
+ static_cast<long>(last_upload_attempt_time));
}
if (options.show_pending_reports) {
@@ -497,7 +526,8 @@ int DatabaseUtilMain(int argc, char* argv[]) {
// If only asked to do one thing, a failure to find the single requested
// report should result in a failure exit status.
if (show_operations + set_operations == 1) {
- fprintf(stderr, "%s: Report not found\n", me.c_str());
+ fprintf(
+ stderr, "%" PRFilePath ": Report not found\n", me.value().c_str());
return EXIT_FAILURE;
}
printf("Report %s not found\n", uuid.ToString().c_str());
@@ -562,6 +592,19 @@ int DatabaseUtilMain(int argc, char* argv[]) {
} // namespace
} // namespace crashpad
+#if defined(OS_POSIX)
int main(int argc, char* argv[]) {
return crashpad::DatabaseUtilMain(argc, argv);
}
+#elif defined(OS_WIN)
+int wmain(int argc, wchar_t* argv[]) {
+ scoped_ptr<char*[]> argv_as_utf8(new char*[argc]);
Mark Mentovai 2015/05/05 22:19:49 I imagine that we’ll want this to be in tool_suppo
scottmg 2015/05/05 23:03:37 Yeah, I did that in the generate_dump CL as it's t
+ std::vector<std::string> storage;
+ storage.reserve(argc);
+ for (int i = 0; i < argc; ++i) {
+ storage.push_back(base::UTF16ToUTF8(argv[i]));
+ argv_as_utf8[i] = &storage[i][0];
+ }
+ return crashpad::DatabaseUtilMain(argc, argv_as_utf8.get());
+}
+#endif // OS_POSIX

Powered by Google App Engine
This is Rietveld 408576698