Commit d3a13492 authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Remove old components/crash/content/app/crash_keys_win.

Bug: 546288
Change-Id: I06388c3d208a37f8743d1b116e50ef133d7a0857
Reviewed-on: https://chromium-review.googlesource.com/c/1324050
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606232}
parent b7352f94
......@@ -199,23 +199,6 @@ source_set("test_support") {
# TODO(crbug.com/565771): This target and :deprecated_breakpad_win should be
# removed.
if (is_win) {
source_set("lib_breakpad") {
visibility = [ ":*" ]
sources = [
"crash_keys_win.cc",
"crash_keys_win.h",
]
deps = [
":lib",
"//base",
"//third_party/breakpad:breakpad_handler",
]
include_dirs = [ "../../../../third_party/breakpad/breakpad/src" ]
}
static_library("deprecated_breakpad_win") {
visibility = [ "//components/nacl/broker:nacl64" ]
......@@ -230,7 +213,6 @@ if (is_win) {
deps = [
":lib",
":lib_breakpad",
"//base",
"//base:base_static",
"//components/crash/core/common",
......@@ -240,6 +222,8 @@ if (is_win) {
"//third_party/breakpad:client",
]
include_dirs = [ "../../../../third_party/breakpad/breakpad/src" ]
libs = [ "userenv.lib" ]
}
}
......@@ -247,7 +231,6 @@ if (is_win) {
source_set("unit_tests") {
testonly = true
sources = [
"crash_keys_win_unittest.cc",
"fallback_crash_handler_launcher_win_unittest.cc",
"fallback_crash_handler_win_unittest.cc",
"fallback_crash_handling_win_unittest.cc",
......@@ -262,7 +245,6 @@ source_set("unit_tests") {
if (is_win) {
deps += [
":lib_breakpad",
":run_as_crashpad_handler",
"//third_party/breakpad:client",
"//third_party/crashpad/crashpad/client:client",
......
......@@ -25,15 +25,16 @@
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/pe_image.h"
#include "base/win/win_util.h"
#include "components/crash/content/app/crash_keys_win.h"
#include "components/crash/content/app/crash_reporter_client.h"
#include "components/crash/content/app/hard_error_handler_win.h"
#include "components/crash/core/common/crash_keys.h"
......@@ -104,6 +105,65 @@ typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle,
NTSTATUS ExitStatus);
char* g_real_terminate_process_stub = nullptr;
// Returns the custom info structure based on the dll in parameter and the
// process type.
google_breakpad::CustomClientInfo* GetCustomInfo(
const std::wstring& exe_path,
const std::wstring& type,
const std::wstring& profile_type,
base::CommandLine* cmd_line,
crash_reporter::CrashReporterClient* crash_client) {
base::string16 version, product, special_build, channel_name;
crash_client->GetProductNameAndVersion(exe_path, &product, &version,
&special_build, &channel_name);
// We only expect this method to be called once per process.
// Common enties
static base::NoDestructor<std::vector<google_breakpad::CustomInfoEntry>>
custom_entries;
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"ver", version.c_str()));
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"prod", product.c_str()));
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"plat", L"Win32"));
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"ptype", type.c_str()));
custom_entries->push_back(google_breakpad::CustomInfoEntry(
L"pid", base::IntToString16(::GetCurrentProcessId()).c_str()));
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"channel", channel_name.c_str()));
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"profile-type", profile_type.c_str()));
if (!special_build.empty()) {
custom_entries->push_back(
google_breakpad::CustomInfoEntry(L"special", special_build.c_str()));
}
// Check whether configuration management controls crash reporting.
bool crash_reporting_enabled = true;
bool controlled_by_policy =
crash_client->ReportingIsEnforcedByPolicy(&crash_reporting_enabled);
bool use_crash_service = !controlled_by_policy &&
(cmd_line->HasSwitch(switches::kNoErrorDialogs) ||
crash_client->IsRunningUnattended());
if (use_crash_service) {
base::string16 crash_dumps_dir_path;
if (crash_client->GetAlternativeCrashDumpLocation(&crash_dumps_dir_path)) {
custom_entries->push_back(google_breakpad::CustomInfoEntry(
L"breakpad-dump-location", crash_dumps_dir_path.c_str()));
}
}
static base::NoDestructor<google_breakpad::CustomClientInfo>
custom_client_info;
custom_client_info->entries = &custom_entries->front();
custom_client_info->count = custom_entries->size();
return custom_client_info.get();
}
} // namespace
// Dumps the current process memory.
......@@ -258,32 +318,6 @@ long WINAPI CloudPrintServiceExceptionFilter(EXCEPTION_POINTERS* info) {
} // namespace
// NOTE: This function is used by SyzyASAN to annotate crash reports. If you
// change the name or signature of this function you will break SyzyASAN
// instrumented releases of Chrome. Please contact syzygy-team@chromium.org
// before doing so!
extern "C" void __declspec(dllexport) __cdecl SetCrashKeyValueImpl(
const wchar_t* key, const wchar_t* value) {
CrashKeysWin* keeper = CrashKeysWin::keeper();
if (!keeper)
return;
// TODO(siggi): This doesn't look quite right - there's NULL deref potential
// here, and an implicit std::wstring conversion. Fixme.
keeper->SetCrashKeyValue(key, value);
}
extern "C" void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(
const wchar_t* key) {
CrashKeysWin* keeper = CrashKeysWin::keeper();
if (!keeper)
return;
// TODO(siggi): This doesn't look quite right - there's NULL deref potential
// here, and an implicit std::wstring conversion. Fixme.
keeper->ClearCrashKeyValue(key);
}
static bool WrapMessageBoxWithSEH(const wchar_t* text, const wchar_t* caption,
UINT flags, bool* exit_now) {
// We wrap the call to MessageBoxW with a SEH handler because it some
......@@ -491,13 +525,9 @@ void InitCrashReporter(const std::string& process_type_switch) {
exe_path[0] = 0;
GetModuleFileNameW(nullptr, exe_path, MAX_PATH);
// This is intentionally leaked.
CrashKeysWin* keeper = new CrashKeysWin();
google_breakpad::CustomClientInfo* custom_info =
keeper->GetCustomInfo(exe_path, process_type, GetProfileType(),
base::CommandLine::ForCurrentProcess(),
GetCrashReporterClient());
google_breakpad::CustomClientInfo* custom_info = GetCustomInfo(
exe_path, process_type, GetProfileType(),
base::CommandLine::ForCurrentProcess(), GetCrashReporterClient());
google_breakpad::ExceptionHandler::MinidumpCallback callback = nullptr;
LPTOP_LEVEL_EXCEPTION_FILTER default_filter = nullptr;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/crash/content/app/crash_keys_win.h"
#include <algorithm>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "components/crash/content/app/crash_reporter_client.h"
#include "third_party/breakpad/breakpad/src/client/windows/common/ipc_protocol.h"
namespace breakpad {
using crash_reporter::CrashReporterClient;
namespace {
const size_t kMaxPluginPathLength = 256;
const size_t kMaxDynamicEntries = 256;
} // namespace
CrashKeysWin* CrashKeysWin::keeper_;
CrashKeysWin::CrashKeysWin()
: custom_entries_(new std::vector<google_breakpad::CustomInfoEntry>),
dynamic_keys_offset_(0) {
DCHECK(!keeper_);
keeper_ = this;
}
CrashKeysWin::~CrashKeysWin() {
DCHECK_EQ(this, keeper_);
keeper_ = nullptr;
}
// Appends the plugin path to |g_custom_entries|.
void CrashKeysWin::SetPluginPath(const std::wstring& path) {
if (path.size() > kMaxPluginPathLength) {
// If the path is too long, truncate from the start rather than the end,
// since we want to be able to recover the DLL name.
SetPluginPath(path.substr(path.size() - kMaxPluginPathLength));
return;
}
// The chunk size without terminator.
const size_t kChunkSize = static_cast<size_t>(
google_breakpad::CustomInfoEntry::kValueMaxLength - 1);
int chunk_index = 0;
size_t chunk_start = 0; // Current position inside |path|
for (chunk_start = 0; chunk_start < path.size(); chunk_index++) {
size_t chunk_length = std::min(kChunkSize, path.size() - chunk_start);
custom_entries_->push_back(google_breakpad::CustomInfoEntry(
base::StringPrintf(L"plugin-path-chunk-%i", chunk_index + 1).c_str(),
path.substr(chunk_start, chunk_length).c_str()));
chunk_start += chunk_length;
}
}
// Appends the breakpad dump path to |g_custom_entries|.
void CrashKeysWin::SetBreakpadDumpPath(CrashReporterClient* crash_client) {
base::string16 crash_dumps_dir_path;
if (crash_client->GetAlternativeCrashDumpLocation(&crash_dumps_dir_path)) {
custom_entries_->push_back(google_breakpad::CustomInfoEntry(
L"breakpad-dump-location", crash_dumps_dir_path.c_str()));
}
}
// Returns the custom info structure based on the dll in parameter and the
// process type.
google_breakpad::CustomClientInfo*
CrashKeysWin::GetCustomInfo(const std::wstring& exe_path,
const std::wstring& type,
const std::wstring& profile_type,
base::CommandLine* cmd_line,
CrashReporterClient* crash_client) {
base::string16 version, product;
base::string16 special_build;
base::string16 channel_name;
crash_client->GetProductNameAndVersion(
exe_path,
&product,
&version,
&special_build,
&channel_name);
// We only expect this method to be called once per process.
// Common enties
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"ver", version.c_str()));
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"prod", product.c_str()));
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"plat", L"Win32"));
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"ptype", type.c_str()));
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(
L"pid", base::IntToString16(::GetCurrentProcessId()).c_str()));
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"channel", channel_name.c_str()));
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"profile-type", profile_type.c_str()));
if (!special_build.empty()) {
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"special", special_build.c_str()));
}
if (type == L"plugin" || type == L"ppapi") {
std::wstring plugin_path = cmd_line->GetSwitchValueNative("plugin-path");
if (!plugin_path.empty())
SetPluginPath(plugin_path);
}
// Check whether configuration management controls crash reporting.
bool crash_reporting_enabled = true;
bool controlled_by_policy = crash_client->ReportingIsEnforcedByPolicy(
&crash_reporting_enabled);
bool use_crash_service = !controlled_by_policy &&
(cmd_line->HasSwitch(switches::kNoErrorDialogs) ||
crash_client->IsRunningUnattended());
if (use_crash_service)
SetBreakpadDumpPath(crash_client);
// Create space for dynamic ad-hoc keys. The names and values are set using
// the API defined in base/debug/crash_logging.h.
dynamic_keys_offset_ = custom_entries_->size();
for (size_t i = 0; i < kMaxDynamicEntries; ++i) {
// The names will be mutated as they are set. Un-numbered since these are
// merely placeholders. The name cannot be empty because Breakpad's
// HTTPUpload will interpret that as an invalid parameter.
custom_entries_->push_back(
google_breakpad::CustomInfoEntry(L"unspecified-crash-key", L""));
}
static google_breakpad::CustomClientInfo custom_client_info;
custom_client_info.entries = &custom_entries_->front();
custom_client_info.count = custom_entries_->size();
return &custom_client_info;
}
void CrashKeysWin::SetCrashKeyValue(
const std::wstring& key, const std::wstring& value) {
// CustomInfoEntry limits the length of key and value. If they exceed
// their maximum length the underlying string handling functions raise
// an exception and prematurely trigger a crash. Truncate here.
std::wstring safe_key(std::wstring(key).substr(
0, google_breakpad::CustomInfoEntry::kNameMaxLength - 1));
std::wstring safe_value(std::wstring(value).substr(
0, google_breakpad::CustomInfoEntry::kValueMaxLength - 1));
// If we already have a value for this key, update it; otherwise, insert
// the new value if we have not exhausted the pre-allocated slots for dynamic
// entries.
base::AutoLock lock(lock_);
DynamicEntriesMap::iterator it = dynamic_entries_.find(safe_key);
google_breakpad::CustomInfoEntry* entry = nullptr;
if (it == dynamic_entries_.end()) {
if (dynamic_entries_.size() >= kMaxDynamicEntries)
return;
entry = &(*custom_entries_)[dynamic_keys_offset_++];
dynamic_entries_.insert(std::make_pair(safe_key, entry));
} else {
entry = it->second;
}
entry->set(safe_key.data(), safe_value.data());
}
void CrashKeysWin::ClearCrashKeyValue(const std::wstring& key) {
base::AutoLock lock(lock_);
std::wstring key_string(key);
DynamicEntriesMap::iterator it = dynamic_entries_.find(key_string);
if (it == dynamic_entries_.end())
return;
it->second->set_value(nullptr);
}
} // namespace breakpad
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_CRASH_CONTENT_APP_CRASH_KEYS_WIN_H_
#define COMPONENTS_CRASH_CONTENT_APP_CRASH_KEYS_WIN_H_
#include <stddef.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/synchronization/lock.h"
namespace base {
class CommandLine;
} // namespace base
namespace crash_reporter {
class CrashReporterClient;
}
namespace google_breakpad {
struct CustomClientInfo;
struct CustomInfoEntry;
}
namespace breakpad {
// Manages the breakpad key/value pair stash, there may only be one instance
// of this class per process at one time.
class CrashKeysWin {
public:
CrashKeysWin();
~CrashKeysWin();
// May only be called once.
// |exe_path| is the path to the executable running, which may be used
// to figure out whether this is a user or system install.
// |type| is the process type, or mode this process is running in e.g.
// something like "browser" or "renderer".
// |profile_type| is a string describing the kind of the user's Windows
// profile, e.g. "mandatory", or "roaming" or similar.
// |cmd_line| is the current process' command line consulted for explicit
// crash reporting flags.
// |crash_client| is consulted for crash reporting settings.
google_breakpad::CustomClientInfo* GetCustomInfo(
const std::wstring& exe_path,
const std::wstring& type,
const std::wstring& profile_type,
base::CommandLine* cmd_line,
crash_reporter::CrashReporterClient* crash_client);
void SetCrashKeyValue(const std::wstring& key, const std::wstring& value);
void ClearCrashKeyValue(const std::wstring& key);
const std::vector<google_breakpad::CustomInfoEntry>& custom_info_entries()
const {
return *custom_entries_;
}
static CrashKeysWin* keeper() { return keeper_; }
private:
// One-time initialization of private key/value pairs.
void SetPluginPath(const std::wstring& path);
void SetBreakpadDumpPath(crash_reporter::CrashReporterClient* crash_client);
// Must not be resized after GetCustomInfo is invoked.
std::unique_ptr<std::vector<google_breakpad::CustomInfoEntry>>
custom_entries_;
typedef std::map<std::wstring, google_breakpad::CustomInfoEntry*>
DynamicEntriesMap;
base::Lock lock_;
// Keeps track of the next index for a new dynamic entry.
size_t dynamic_keys_offset_; // Under lock_.
// Maintains key->entry information for dynamic key/value entries
// in custom_entries_.
DynamicEntriesMap dynamic_entries_; // Under lock_.
// Stores the sole instance of this class allowed per process.
static CrashKeysWin* keeper_;
DISALLOW_COPY_AND_ASSIGN(CrashKeysWin);
};
} // namespace breakpad
#endif // COMPONENTS_CRASH_CONTENT_APP_CRASH_KEYS_WIN_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/crash/content/app/crash_keys_win.h"
#include <stddef.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/stringprintf.h"
#include "components/crash/content/app/crash_reporter_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/breakpad/breakpad/src/client/windows/common/ipc_protocol.h"
namespace breakpad {
using testing::_;
using testing::DoAll;
using testing::Return;
using testing::SetArgPointee;
class MockCrashReporterClient : public crash_reporter::CrashReporterClient {
public:
MOCK_METHOD1(GetAlternativeCrashDumpLocation,
bool(base::string16* crash_dir));
MOCK_METHOD5(GetProductNameAndVersion, void(const base::string16& exe_path,
base::string16* product_name,
base::string16* version,
base::string16* special_build,
base::string16* channel_name));
MOCK_METHOD3(ShouldShowRestartDialog, bool(base::string16* title,
base::string16* message,
bool* is_rtl_locale));
MOCK_METHOD0(AboutToRestart, bool());
MOCK_METHOD1(GetDeferredUploadsSupported, bool(bool is_per_user_install));
MOCK_METHOD0(GetIsPerUserInstall, bool());
MOCK_METHOD0(GetShouldDumpLargerDumps, bool());
MOCK_METHOD0(GetResultCodeRespawnFailed, int());
MOCK_METHOD0(InitBrowserCrashDumpsRegKey, void());
MOCK_METHOD1(RecordCrashDumpAttempt, void(bool is_real_crash));
MOCK_METHOD2(GetProductNameAndVersion, void(std::string* product_name,
std::string* version));
MOCK_METHOD0(GetReporterLogFilename, base::FilePath());
MOCK_METHOD1(GetCrashDumpLocation, bool(base::string16* crash_dir));
MOCK_METHOD0(IsRunningUnattended, bool());
MOCK_METHOD0(GetCollectStatsConsent, bool());
MOCK_METHOD1(ReportingIsEnforcedByPolicy, bool(bool* breakpad_enabled));
MOCK_METHOD0(GetAndroidMinidumpDescriptor, int());
MOCK_METHOD1(EnableBreakpadForProcess, bool(const std::string& process_type));
};
class CrashKeysWinTest : public testing::Test {
public:
size_t CountKeyValueOccurences(
const google_breakpad::CustomClientInfo* client_info,
const wchar_t* key, const wchar_t* value);
protected:
testing::StrictMock<MockCrashReporterClient> crash_client_;
};
size_t CrashKeysWinTest::CountKeyValueOccurences(
const google_breakpad::CustomClientInfo* client_info,
const wchar_t* key, const wchar_t* value) {
size_t occurrences = 0;
for (size_t i = 0; i < client_info->count; ++i) {
if (wcscmp(client_info->entries[i].name, key) == 0 &&
wcscmp(client_info->entries[i].value, value) == 0) {
++occurrences;
}
}
return occurrences;
}
TEST_F(CrashKeysWinTest, RecordsSelf) {
ASSERT_FALSE(CrashKeysWin::keeper());
{
CrashKeysWin crash_keys;
ASSERT_EQ(&crash_keys, CrashKeysWin::keeper());
}
ASSERT_FALSE(CrashKeysWin::keeper());
}
// Tests the crash keys set up for the most common official build consumer
// scenario. No policy controls, not running unattended and no explicit
// switches.
TEST_F(CrashKeysWinTest, OfficialLikeKeys) {
CrashKeysWin crash_keys;
const base::string16 kExePath(L"C:\\temp\\exe_path.exe");
// The exe path ought to get passed through to the breakpad client.
EXPECT_CALL(crash_client_, GetProductNameAndVersion(kExePath, _, _, _, _))
.WillRepeatedly(DoAll(
SetArgPointee<1>(L"SomeProdName"),
SetArgPointee<2>(L"1.2.3.4"),
SetArgPointee<3>(L""),
SetArgPointee<4>(L"-devm")));
EXPECT_CALL(crash_client_, GetAlternativeCrashDumpLocation(_))
.WillRepeatedly(DoAll(
SetArgPointee<0>(L"C:\\temp"),
Return(false)));
EXPECT_CALL(crash_client_, ReportingIsEnforcedByPolicy(_))
.WillRepeatedly(Return(false));
EXPECT_CALL(crash_client_, IsRunningUnattended())
.WillRepeatedly(Return(false));
// Provide an empty command line.
base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM);
google_breakpad::CustomClientInfo* info =
crash_keys.GetCustomInfo(kExePath,
L"made_up_type",
L"temporary",
&cmd_line,
&crash_client_);
ASSERT_TRUE(info != nullptr);
ASSERT_TRUE(info->entries != nullptr);
// We expect 7 fixed keys and a "freeboard" of 256 keys for dynamic entries.
EXPECT_EQ(256U + 7U, info->count);
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"ver", L"1.2.3.4"));
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"prod", L"SomeProdName"));
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"plat", L"Win32"));
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"ptype", L"made_up_type"));
std::wstring pid_str(base::StringPrintf(L"%d", ::GetCurrentProcessId()));
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"pid", pid_str.c_str()));
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"channel", L"-devm"));
EXPECT_EQ(1u, CountKeyValueOccurences(info, L"profile-type", L"temporary"));
EXPECT_EQ(256u, CountKeyValueOccurences(info, L"unspecified-crash-key", L""));
}
} // namespace breakpad
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment