Skip to content

Commit

Permalink
Expose the Crashpad database path for direct use in the browser process.
Browse files Browse the repository at this point in the history
This also paves the way for removing the awkward cross-module marshaling
of crash reports. With the Crasphad database path available, it's a
simple matter to construct a new database instance at need.

Bug: 806661
Change-Id: Ifd64f02bd7855de32163d91b6d2ad52404f9883e
Reviewed-on: https://chromium-review.googlesource.com/911594
Reviewed-by: Robert Shield <robertshield@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535792}
  • Loading branch information
sigurasg authored and Commit Bot committed Feb 9, 2018
1 parent 8986047 commit 70c33ff
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions chrome_elf/chrome_elf_x64.def
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ EXPORTS

; From components/crash/content/app/crash_export_stubs.cc
CrashForException_ExportThunk
GetCrashpadDatabasePath_ExportThunk
GetCrashReports_ExportThunk
InjectDumpForHungInput_ExportThunk
RequestSingleCrashUpload_ExportThunk
Expand Down
1 change: 1 addition & 0 deletions chrome_elf/chrome_elf_x86.def
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ EXPORTS

; From components/crash/content/app/crash_export_stubs.cc
CrashForException_ExportThunk
GetCrashpadDatabasePath_ExportThunk
GetCrashReports_ExportThunk
InjectDumpForHungInput_ExportThunk
RequestSingleCrashUpload_ExportThunk
Expand Down
4 changes: 4 additions & 0 deletions components/crash/content/app/crash_export_stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ HANDLE InjectDumpForHungInput_ExportThunk(HANDLE process) {
return nullptr;
}

const wchar_t* GetCrashpadDatabasePath_ExportThunk() {
return nullptr;
}

#if defined(ARCH_CPU_X86_64)

void RegisterNonABICompliantCodeRange_ExportThunk(void* start,
Expand Down
4 changes: 4 additions & 0 deletions components/crash/content/app/crash_export_thunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ HANDLE InjectDumpForHungInput_ExportThunk(HANDLE process) {
nullptr);
}

const wchar_t* GetCrashpadDatabasePath_ExportThunk() {
return crash_reporter::GetCrashpadDatabasePathImpl();
}

#if defined(ARCH_CPU_X86_64)

void RegisterNonABICompliantCodeRange_ExportThunk(void* start,
Expand Down
3 changes: 3 additions & 0 deletions components/crash/content/app/crash_export_thunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ void SetUploadConsent_ExportThunk(bool consent);
// This method is used solely to classify hung input.
HANDLE InjectDumpForHungInput_ExportThunk(HANDLE process);

// Returns the crashpad database path.
const wchar_t* GetCrashpadDatabasePath_ExportThunk();

#if defined(ARCH_CPU_X86_64)
// V8 support functions.
void RegisterNonABICompliantCodeRange_ExportThunk(void* start,
Expand Down
26 changes: 26 additions & 0 deletions components/crash/content/app/crashpad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace crash_reporter {

namespace {

base::FilePath* g_database_path;

crashpad::CrashReportDatabase* g_database;

bool LogMessageHandler(int severity,
Expand Down Expand Up @@ -87,6 +89,13 @@ bool LogMessageHandler(int severity,
return false;
}

void InitializeDatabasePath(const base::FilePath& database_path) {
DCHECK(!g_database_path);

// Intentionally leaked.
g_database_path = new base::FilePath(database_path);
}

void InitializeCrashpadImpl(bool initial_client,
const std::string& process_type,
const std::string& user_data_dir,
Expand Down Expand Up @@ -172,6 +181,8 @@ void InitializeCrashpadImpl(bool initial_client,
const bool should_initialize_database_and_set_upload_policy = initial_client;
#endif
if (should_initialize_database_and_set_upload_policy) {
InitializeDatabasePath(database_path);

g_database =
crashpad::CrashReportDatabase::Initialize(database_path).release();

Expand Down Expand Up @@ -275,6 +286,14 @@ void RequestSingleCrashUpload(const std::string& local_id) {
#endif
}

base::FilePath GetCrashpadDatabasePath() {
#if defined(OS_WIN)
return base::FilePath(GetCrashpadDatabasePath_ExportThunk());
#else
return base::FilePath(GetCrashpadDatabasePathImpl());
#endif
}

void GetReportsImpl(std::vector<Report>* reports) {
reports->clear();

Expand Down Expand Up @@ -343,4 +362,11 @@ void RequestSingleCrashUploadImpl(const std::string& local_id) {
g_database->RequestUpload(uuid);
}

base::FilePath::StringType::const_pointer GetCrashpadDatabasePathImpl() {
if (!g_database_path)
return nullptr;

return g_database_path->value().c_str();
}

} // namespace crash_reporter
6 changes: 6 additions & 0 deletions components/crash/content/app/crashpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ void RequestSingleCrashUpload(const std::string& local_id);

void DumpWithoutCrashing();

// Returns the Crashpad database path, only valid in the browser.
base::FilePath GetCrashpadDatabasePath();

// The implementation function for GetReports.
void GetReportsImpl(std::vector<Report>* reports);

// The implementation function for RequestSingleCrashUpload.
void RequestSingleCrashUploadImpl(const std::string& local_id);

// The implementation function for GetCrashpadDatabasePath.
base::FilePath::StringType::const_pointer GetCrashpadDatabasePathImpl();

namespace internal {

#if defined(OS_WIN)
Expand Down

0 comments on commit 70c33ff

Please sign in to comment.