mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-25 23:06:23 +02:00
* Updated breakpad to latest version.
This commit is contained in:
0
thirdparty/breakpad/client/windows/breakpad_client.gyp
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/breakpad_client.gyp
vendored
Executable file → Normal file
6
thirdparty/breakpad/client/windows/build/common.gypi
vendored
Executable file → Normal file
6
thirdparty/breakpad/client/windows/build/common.gypi
vendored
Executable file → Normal file
@@ -191,10 +191,6 @@
|
||||
# Currently ignored on Windows.
|
||||
'coverage%': 0,
|
||||
|
||||
# Overridable specification for potential use of alternative
|
||||
# JavaScript engines.
|
||||
'javascript_engine%': 'v8',
|
||||
|
||||
# Although base/allocator lets you select a heap library via an
|
||||
# environment variable, the libcmt shim it uses sometimes gets in
|
||||
# the way. To disable it entirely, and switch to normal msvcrt, do e.g.
|
||||
@@ -272,7 +268,7 @@
|
||||
|
||||
# Enable new NPDevice API.
|
||||
'enable_new_npdevice_api%': 0,
|
||||
|
||||
|
||||
'conditions': [
|
||||
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
|
||||
# This will set gcc_version to XY if you are running gcc X.Y.*.
|
||||
|
0
thirdparty/breakpad/client/windows/build/external_code.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/external_code.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/internal/release_defaults.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/internal/release_defaults.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/internal/release_impl.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/internal/release_impl.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/internal/release_impl_official.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/internal/release_impl_official.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/release.gypi
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/build/release.gypi
vendored
Executable file → Normal file
@@ -40,13 +40,30 @@ class AutoCriticalSection {
|
||||
public:
|
||||
// Creates a new instance with the given critical section object
|
||||
// and enters the critical section immediately.
|
||||
explicit AutoCriticalSection(CRITICAL_SECTION* cs) : cs_(cs) {
|
||||
explicit AutoCriticalSection(CRITICAL_SECTION* cs) : cs_(cs), taken_(false) {
|
||||
assert(cs_);
|
||||
EnterCriticalSection(cs_);
|
||||
Acquire();
|
||||
}
|
||||
|
||||
// Destructor: leaves the critical section.
|
||||
~AutoCriticalSection() {
|
||||
if (taken_) {
|
||||
Release();
|
||||
}
|
||||
}
|
||||
|
||||
// Enters the critical section. Recursive Acquire() calls are not allowed.
|
||||
void Acquire() {
|
||||
assert(!taken_);
|
||||
EnterCriticalSection(cs_);
|
||||
taken_ = true;
|
||||
}
|
||||
|
||||
// Leaves the critical section. The caller should not call Release() unless
|
||||
// the critical seciton has been entered already.
|
||||
void Release() {
|
||||
assert(taken_);
|
||||
taken_ = false;
|
||||
LeaveCriticalSection(cs_);
|
||||
}
|
||||
|
||||
@@ -56,6 +73,7 @@ class AutoCriticalSection {
|
||||
AutoCriticalSection& operator=(const AutoCriticalSection&);
|
||||
|
||||
CRITICAL_SECTION* cs_;
|
||||
bool taken_;
|
||||
};
|
||||
|
||||
} // namespace google_breakpad
|
||||
|
@@ -30,8 +30,8 @@
|
||||
#ifndef CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__
|
||||
#define CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__
|
||||
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
#include <Windows.h>
|
||||
#include <DbgHelp.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "common/windows/string_utils-inl.h"
|
||||
@@ -90,7 +90,8 @@ enum MessageTag {
|
||||
MESSAGE_TAG_NONE = 0,
|
||||
MESSAGE_TAG_REGISTRATION_REQUEST = 1,
|
||||
MESSAGE_TAG_REGISTRATION_RESPONSE = 2,
|
||||
MESSAGE_TAG_REGISTRATION_ACK = 3
|
||||
MESSAGE_TAG_REGISTRATION_ACK = 3,
|
||||
MESSAGE_TAG_UPLOAD_REQUEST = 4
|
||||
};
|
||||
|
||||
struct CustomClientInfo {
|
||||
@@ -102,7 +103,7 @@ struct CustomClientInfo {
|
||||
struct ProtocolMessage {
|
||||
ProtocolMessage()
|
||||
: tag(MESSAGE_TAG_NONE),
|
||||
pid(0),
|
||||
id(0),
|
||||
dump_type(MiniDumpNormal),
|
||||
thread_id(0),
|
||||
exception_pointers(NULL),
|
||||
@@ -115,7 +116,7 @@ struct ProtocolMessage {
|
||||
|
||||
// Creates an instance with the given parameters.
|
||||
ProtocolMessage(MessageTag arg_tag,
|
||||
DWORD arg_pid,
|
||||
DWORD arg_id,
|
||||
MINIDUMP_TYPE arg_dump_type,
|
||||
DWORD* arg_thread_id,
|
||||
EXCEPTION_POINTERS** arg_exception_pointers,
|
||||
@@ -125,7 +126,7 @@ struct ProtocolMessage {
|
||||
HANDLE arg_dump_generated_handle,
|
||||
HANDLE arg_server_alive)
|
||||
: tag(arg_tag),
|
||||
pid(arg_pid),
|
||||
id(arg_id),
|
||||
dump_type(arg_dump_type),
|
||||
thread_id(arg_thread_id),
|
||||
exception_pointers(arg_exception_pointers),
|
||||
@@ -139,8 +140,9 @@ struct ProtocolMessage {
|
||||
// Tag in the message.
|
||||
MessageTag tag;
|
||||
|
||||
// Process id.
|
||||
DWORD pid;
|
||||
// The id for this message. This may be either a process id or a crash id
|
||||
// depending on the type of message.
|
||||
DWORD id;
|
||||
|
||||
// Dump type requested.
|
||||
MINIDUMP_TYPE dump_type;
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "client/windows/common/ipc_protocol.h"
|
||||
|
||||
static const wchar_t kCustomInfoProcessUptimeName[] = L"ptime";
|
||||
static const size_t kMaxCustomInfoEntries = 4096;
|
||||
|
||||
namespace google_breakpad {
|
||||
|
||||
@@ -52,7 +53,8 @@ ClientInfo::ClientInfo(CrashGenerationServer* crash_server,
|
||||
dump_requested_handle_(NULL),
|
||||
dump_generated_handle_(NULL),
|
||||
dump_request_wait_handle_(NULL),
|
||||
process_exit_wait_handle_(NULL) {
|
||||
process_exit_wait_handle_(NULL),
|
||||
crash_id_(NULL) {
|
||||
GetSystemTimeAsFileTime(&start_time_);
|
||||
}
|
||||
|
||||
@@ -62,6 +64,12 @@ bool ClientInfo::Initialize() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The crash_id will be the low order word of the process creation time.
|
||||
FILETIME creation_time, exit_time, kernel_time, user_time;
|
||||
if (GetProcessTimes(process_handle_, &creation_time, &exit_time,
|
||||
&kernel_time, &user_time))
|
||||
crash_id_ = creation_time.dwLowDateTime;
|
||||
|
||||
dump_requested_handle_ = CreateEvent(NULL, // Security attributes.
|
||||
TRUE, // Manual reset.
|
||||
FALSE, // Initial state.
|
||||
@@ -160,6 +168,9 @@ void ClientInfo::SetProcessUptime() {
|
||||
}
|
||||
|
||||
bool ClientInfo::PopulateCustomInfo() {
|
||||
if (custom_client_info_.count > kMaxCustomInfoEntries)
|
||||
return false;
|
||||
|
||||
SIZE_T bytes_count = 0;
|
||||
SIZE_T read_count = sizeof(CustomInfoEntry) * custom_client_info_.count;
|
||||
|
||||
|
@@ -65,6 +65,7 @@ class ClientInfo {
|
||||
HANDLE process_handle() const { return process_handle_; }
|
||||
HANDLE dump_requested_handle() const { return dump_requested_handle_; }
|
||||
HANDLE dump_generated_handle() const { return dump_generated_handle_; }
|
||||
DWORD crash_id() const { return crash_id_; }
|
||||
|
||||
HANDLE dump_request_wait_handle() const {
|
||||
return dump_request_wait_handle_;
|
||||
@@ -160,6 +161,11 @@ class ClientInfo {
|
||||
// for the client process when it signals a crash.
|
||||
FILETIME start_time_;
|
||||
|
||||
// The crash id which can be used to request an upload. This will be the
|
||||
// value of the low order dword of the process creation time for the process
|
||||
// being dumped.
|
||||
DWORD crash_id_;
|
||||
|
||||
// Disallow copy ctor and operator=.
|
||||
ClientInfo(const ClientInfo& client_info);
|
||||
ClientInfo& operator=(const ClientInfo& client_info);
|
||||
|
0
thirdparty/breakpad/client/windows/crash_generation/crash_generation.gyp
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/crash_generation/crash_generation.gyp
vendored
Executable file → Normal file
@@ -167,6 +167,23 @@ bool CrashGenerationClient::Register() {
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CrashGenerationClient::RequestUpload(DWORD crash_id) {
|
||||
HANDLE pipe = ConnectToServer();
|
||||
if (!pipe) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CustomClientInfo custom_info = {NULL, 0};
|
||||
ProtocolMessage msg(MESSAGE_TAG_UPLOAD_REQUEST, crash_id,
|
||||
static_cast<MINIDUMP_TYPE>(NULL), NULL, NULL, NULL,
|
||||
custom_info, NULL, NULL, NULL);
|
||||
DWORD bytes_count = 0;
|
||||
bool success = WriteFile(pipe, &msg, sizeof(msg), &bytes_count, NULL) != 0;
|
||||
|
||||
CloseHandle(pipe);
|
||||
return success;
|
||||
}
|
||||
|
||||
HANDLE CrashGenerationClient::ConnectToServer() {
|
||||
HANDLE pipe = ConnectToPipe(pipe_name_.c_str(),
|
||||
kPipeDesiredAccess,
|
||||
@@ -223,7 +240,7 @@ bool CrashGenerationClient::RegisterClient(HANDLE pipe) {
|
||||
crash_event_ = reply.dump_request_handle;
|
||||
crash_generated_ = reply.dump_generated_handle;
|
||||
server_alive_ = reply.server_alive_handle;
|
||||
server_process_id_ = reply.pid;
|
||||
server_process_id_ = reply.id;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -261,7 +278,7 @@ HANDLE CrashGenerationClient::ConnectToPipe(const wchar_t* pipe_name,
|
||||
bool CrashGenerationClient::ValidateResponse(
|
||||
const ProtocolMessage& msg) const {
|
||||
return (msg.tag == MESSAGE_TAG_REGISTRATION_RESPONSE) &&
|
||||
(msg.pid != 0) &&
|
||||
(msg.id != 0) &&
|
||||
(msg.dump_request_handle != NULL) &&
|
||||
(msg.dump_generated_handle != NULL) &&
|
||||
(msg.server_alive_handle != NULL);
|
||||
|
@@ -73,6 +73,10 @@ class CrashGenerationClient {
|
||||
// Returns true if the registration is successful; false otherwise.
|
||||
bool Register();
|
||||
|
||||
// Requests the crash server to upload a previous dump with the
|
||||
// given crash id.
|
||||
bool RequestUpload(DWORD crash_id);
|
||||
|
||||
bool RequestDump(EXCEPTION_POINTERS* ex_info,
|
||||
MDRawAssertionInfo* assert_info);
|
||||
|
||||
|
@@ -84,11 +84,12 @@ static const int kShutdownDelayMs = 10000;
|
||||
static const int kShutdownSleepIntervalMs = 5;
|
||||
|
||||
static bool IsClientRequestValid(const ProtocolMessage& msg) {
|
||||
return msg.tag == MESSAGE_TAG_REGISTRATION_REQUEST &&
|
||||
msg.pid != 0 &&
|
||||
msg.thread_id != NULL &&
|
||||
msg.exception_pointers != NULL &&
|
||||
msg.assert_info != NULL;
|
||||
return msg.tag == MESSAGE_TAG_UPLOAD_REQUEST ||
|
||||
(msg.tag == MESSAGE_TAG_REGISTRATION_REQUEST &&
|
||||
msg.id != 0 &&
|
||||
msg.thread_id != NULL &&
|
||||
msg.exception_pointers != NULL &&
|
||||
msg.assert_info != NULL);
|
||||
}
|
||||
|
||||
CrashGenerationServer::CrashGenerationServer(
|
||||
@@ -100,6 +101,8 @@ CrashGenerationServer::CrashGenerationServer(
|
||||
void* dump_context,
|
||||
OnClientExitedCallback exit_callback,
|
||||
void* exit_context,
|
||||
OnClientUploadRequestCallback upload_request_callback,
|
||||
void* upload_context,
|
||||
bool generate_dumps,
|
||||
const std::wstring* dump_path)
|
||||
: pipe_name_(pipe_name),
|
||||
@@ -113,6 +116,8 @@ CrashGenerationServer::CrashGenerationServer(
|
||||
dump_context_(dump_context),
|
||||
exit_callback_(exit_callback),
|
||||
exit_context_(exit_context),
|
||||
upload_request_callback_(upload_request_callback),
|
||||
upload_context_(upload_context),
|
||||
generate_dumps_(generate_dumps),
|
||||
dump_generator_(NULL),
|
||||
server_state_(IPC_SERVER_STATE_UNINITIALIZED),
|
||||
@@ -120,7 +125,7 @@ CrashGenerationServer::CrashGenerationServer(
|
||||
overlapped_(),
|
||||
client_info_(NULL),
|
||||
cleanup_item_count_(0) {
|
||||
InitializeCriticalSection(&clients_sync_);
|
||||
InitializeCriticalSection(&sync_);
|
||||
|
||||
if (dump_path) {
|
||||
dump_generator_.reset(new MinidumpGenerator(*dump_path));
|
||||
@@ -128,38 +133,41 @@ CrashGenerationServer::CrashGenerationServer(
|
||||
}
|
||||
|
||||
CrashGenerationServer::~CrashGenerationServer() {
|
||||
// Indicate to existing threads that server is shutting down.
|
||||
shutting_down_ = true;
|
||||
|
||||
// Even if there are no current worker threads running, it is possible that
|
||||
// an I/O request is pending on the pipe right now but not yet done. In fact,
|
||||
// it's very likely this is the case unless we are in an ERROR state. If we
|
||||
// don't wait for the pending I/O to be done, then when the I/O completes,
|
||||
// it may write to invalid memory. AppVerifier will flag this problem too.
|
||||
// So we disconnect from the pipe and then wait for the server to get into
|
||||
// error state so that the pending I/O will fail and get cleared.
|
||||
DisconnectNamedPipe(pipe_);
|
||||
int num_tries = 100;
|
||||
while (num_tries-- && server_state_ != IPC_SERVER_STATE_ERROR) {
|
||||
Sleep(10);
|
||||
}
|
||||
|
||||
// Unregister wait on the pipe.
|
||||
if (pipe_wait_handle_) {
|
||||
// Wait for already executing callbacks to finish.
|
||||
UnregisterWaitEx(pipe_wait_handle_, INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
// Close the pipe to avoid further client connections.
|
||||
if (pipe_) {
|
||||
CloseHandle(pipe_);
|
||||
}
|
||||
|
||||
// Request all ClientInfo objects to unregister all waits.
|
||||
// New scope to hold the lock for the shortest time.
|
||||
// New scope to release the lock automatically.
|
||||
{
|
||||
AutoCriticalSection lock(&clients_sync_);
|
||||
AutoCriticalSection lock(&sync_);
|
||||
|
||||
// Indicate to existing threads that server is shutting down.
|
||||
shutting_down_ = true;
|
||||
|
||||
// Even if there are no current worker threads running, it is possible that
|
||||
// an I/O request is pending on the pipe right now but not yet done.
|
||||
// In fact, it's very likely this is the case unless we are in an ERROR
|
||||
// state. If we don't wait for the pending I/O to be done, then when the I/O
|
||||
// completes, it may write to invalid memory. AppVerifier will flag this
|
||||
// problem too. So we disconnect from the pipe and then wait for the server
|
||||
// to get into error state so that the pending I/O will fail and get
|
||||
// cleared.
|
||||
DisconnectNamedPipe(pipe_);
|
||||
int num_tries = 100;
|
||||
while (num_tries-- && server_state_ != IPC_SERVER_STATE_ERROR) {
|
||||
lock.Release();
|
||||
Sleep(10);
|
||||
lock.Acquire();
|
||||
}
|
||||
|
||||
// Unregister wait on the pipe.
|
||||
if (pipe_wait_handle_) {
|
||||
// Wait for already executing callbacks to finish.
|
||||
UnregisterWaitEx(pipe_wait_handle_, INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
// Close the pipe to avoid further client connections.
|
||||
if (pipe_) {
|
||||
CloseHandle(pipe_);
|
||||
}
|
||||
|
||||
// Request all ClientInfo objects to unregister all waits.
|
||||
std::list<ClientInfo*>::iterator iter;
|
||||
for (iter = clients_.begin(); iter != clients_.end(); ++iter) {
|
||||
ClientInfo* client_info = *iter;
|
||||
@@ -180,33 +188,35 @@ CrashGenerationServer::~CrashGenerationServer() {
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up all the ClientInfo objects.
|
||||
// New scope to hold the lock for the shortest time.
|
||||
{
|
||||
AutoCriticalSection lock(&clients_sync_);
|
||||
AutoCriticalSection lock(&sync_);
|
||||
|
||||
// Clean up all the ClientInfo objects.
|
||||
std::list<ClientInfo*>::iterator iter;
|
||||
for (iter = clients_.begin(); iter != clients_.end(); ++iter) {
|
||||
ClientInfo* client_info = *iter;
|
||||
delete client_info;
|
||||
}
|
||||
|
||||
if (server_alive_handle_) {
|
||||
// Release the mutex before closing the handle so that clients requesting
|
||||
// dumps wait for a long time for the server to generate a dump.
|
||||
ReleaseMutex(server_alive_handle_);
|
||||
CloseHandle(server_alive_handle_);
|
||||
}
|
||||
|
||||
if (overlapped_.hEvent) {
|
||||
CloseHandle(overlapped_.hEvent);
|
||||
}
|
||||
}
|
||||
|
||||
if (server_alive_handle_) {
|
||||
// Release the mutex before closing the handle so that clients requesting
|
||||
// dumps wait for a long time for the server to generate a dump.
|
||||
ReleaseMutex(server_alive_handle_);
|
||||
CloseHandle(server_alive_handle_);
|
||||
}
|
||||
|
||||
if (overlapped_.hEvent) {
|
||||
CloseHandle(overlapped_.hEvent);
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&clients_sync_);
|
||||
DeleteCriticalSection(&sync_);
|
||||
}
|
||||
|
||||
bool CrashGenerationServer::Start() {
|
||||
AutoCriticalSection lock(&sync_);
|
||||
|
||||
if (server_state_ != IPC_SERVER_STATE_UNINITIALIZED) {
|
||||
return false;
|
||||
}
|
||||
@@ -416,9 +426,16 @@ void CrashGenerationServer::HandleReadDoneState() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg_.tag == MESSAGE_TAG_UPLOAD_REQUEST) {
|
||||
if (upload_request_callback_)
|
||||
upload_request_callback_(upload_context_, msg_.id);
|
||||
EnterStateImmediately(IPC_SERVER_STATE_DISCONNECTING);
|
||||
return;
|
||||
}
|
||||
|
||||
scoped_ptr<ClientInfo> client_info(
|
||||
new ClientInfo(this,
|
||||
msg_.pid,
|
||||
msg_.id,
|
||||
msg_.dump_type,
|
||||
msg_.thread_id,
|
||||
msg_.exception_pointers,
|
||||
@@ -582,7 +599,7 @@ void CrashGenerationServer::EnterStateImmediately(IPCServerState state) {
|
||||
bool CrashGenerationServer::PrepareReply(const ClientInfo& client_info,
|
||||
ProtocolMessage* reply) const {
|
||||
reply->tag = MESSAGE_TAG_REGISTRATION_RESPONSE;
|
||||
reply->pid = GetCurrentProcessId();
|
||||
reply->id = GetCurrentProcessId();
|
||||
|
||||
if (CreateClientHandles(client_info, reply)) {
|
||||
return true;
|
||||
@@ -670,6 +687,8 @@ bool CrashGenerationServer::RespondToClient(ClientInfo* client_info) {
|
||||
// implements the state machine described in ReadMe.txt along with the
|
||||
// helper methods HandleXXXState.
|
||||
void CrashGenerationServer::HandleConnectionRequest() {
|
||||
AutoCriticalSection lock(&sync_);
|
||||
|
||||
// If we are shutting doen then get into ERROR state, reset the event so more
|
||||
// workers don't run and return immediately.
|
||||
if (shutting_down_) {
|
||||
@@ -756,7 +775,7 @@ bool CrashGenerationServer::AddClient(ClientInfo* client_info) {
|
||||
|
||||
// New scope to hold the lock for the shortest time.
|
||||
{
|
||||
AutoCriticalSection lock(&clients_sync_);
|
||||
AutoCriticalSection lock(&sync_);
|
||||
clients_.push_back(client_info);
|
||||
}
|
||||
|
||||
@@ -793,6 +812,7 @@ void CALLBACK CrashGenerationServer::OnClientEnd(void* context, BOOLEAN) {
|
||||
CrashGenerationServer* crash_server = client_info->crash_server();
|
||||
assert(crash_server);
|
||||
|
||||
client_info->UnregisterWaits();
|
||||
InterlockedIncrement(&crash_server->cleanup_item_count_);
|
||||
|
||||
if (!QueueUserWorkItem(CleanupClient, context, WT_EXECUTEDEFAULT)) {
|
||||
@@ -823,7 +843,7 @@ void CrashGenerationServer::DoCleanup(ClientInfo* client_info) {
|
||||
|
||||
// Start a new scope to release lock automatically.
|
||||
{
|
||||
AutoCriticalSection lock(&clients_sync_);
|
||||
AutoCriticalSection lock(&sync_);
|
||||
clients_.remove(client_info);
|
||||
}
|
||||
|
||||
|
@@ -59,6 +59,9 @@ class CrashGenerationServer {
|
||||
typedef void (*OnClientExitedCallback)(void* context,
|
||||
const ClientInfo* client_info);
|
||||
|
||||
typedef void (*OnClientUploadRequestCallback)(void* context,
|
||||
const DWORD crash_id);
|
||||
|
||||
// Creates an instance with the given parameters.
|
||||
//
|
||||
// Parameter pipe_name: Name of the Windows named pipe
|
||||
@@ -86,6 +89,8 @@ class CrashGenerationServer {
|
||||
void* dump_context,
|
||||
OnClientExitedCallback exit_callback,
|
||||
void* exit_context,
|
||||
OnClientUploadRequestCallback upload_request_callback,
|
||||
void* upload_context,
|
||||
bool generate_dumps,
|
||||
const std::wstring* dump_path);
|
||||
|
||||
@@ -211,8 +216,9 @@ class CrashGenerationServer {
|
||||
// asynchronous IO operation.
|
||||
void EnterStateWhenSignaled(IPCServerState state);
|
||||
|
||||
// Sync object for thread-safe access to the shared list of clients.
|
||||
CRITICAL_SECTION clients_sync_;
|
||||
// Sync object for thread-safe access to the shared list of clients and
|
||||
// the server's state.
|
||||
CRITICAL_SECTION sync_;
|
||||
|
||||
// List of clients.
|
||||
std::list<ClientInfo*> clients_;
|
||||
@@ -250,6 +256,12 @@ class CrashGenerationServer {
|
||||
// Context for client process exit callback.
|
||||
void* exit_context_;
|
||||
|
||||
// Callback for upload request.
|
||||
OnClientUploadRequestCallback upload_request_callback_;
|
||||
|
||||
// Context for upload request callback.
|
||||
void* upload_context_;
|
||||
|
||||
// Whether to generate dumps.
|
||||
bool generate_dumps_;
|
||||
|
||||
@@ -260,10 +272,10 @@ class CrashGenerationServer {
|
||||
// Note that since we restrict the pipe to one instance, we
|
||||
// only need to keep one state of the server. Otherwise, server
|
||||
// would have one state per client it is talking to.
|
||||
volatile IPCServerState server_state_;
|
||||
IPCServerState server_state_;
|
||||
|
||||
// Whether the server is shutting down.
|
||||
volatile bool shutting_down_;
|
||||
bool shutting_down_;
|
||||
|
||||
// Overlapped instance for async I/O on the pipe.
|
||||
OVERLAPPED overlapped_;
|
||||
|
@@ -27,7 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <objbase.h>
|
||||
#include <ObjBase.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
@@ -39,8 +39,6 @@
|
||||
#include "client/windows/handler/exception_handler.h"
|
||||
#include "common/windows/guid_string.h"
|
||||
|
||||
typedef VOID (WINAPI *RtlCaptureContextPtr) (PCONTEXT pContextRecord);
|
||||
|
||||
namespace google_breakpad {
|
||||
|
||||
static const int kWaitForHandlerThreadMs = 60000;
|
||||
@@ -223,8 +221,8 @@ void ExceptionHandler::Initialize(const wstring& dump_path,
|
||||
previous_iph_ = _set_invalid_parameter_handler(HandleInvalidParameter);
|
||||
#endif // _MSC_VER >= 1400
|
||||
|
||||
// if (handler_types & HANDLER_PURECALL)
|
||||
// previous_pch_ = _set_purecall_handler(HandlePureVirtualCall);
|
||||
if (handler_types & HANDLER_PURECALL)
|
||||
previous_pch_ = _set_purecall_handler(HandlePureVirtualCall);
|
||||
|
||||
LeaveCriticalSection(&handler_stack_critical_section_);
|
||||
}
|
||||
@@ -250,8 +248,8 @@ ExceptionHandler::~ExceptionHandler() {
|
||||
_set_invalid_parameter_handler(previous_iph_);
|
||||
#endif // _MSC_VER >= 1400
|
||||
|
||||
// if (handler_types_ & HANDLER_PURECALL)
|
||||
// _set_purecall_handler(previous_pch_);
|
||||
if (handler_types_ & HANDLER_PURECALL)
|
||||
_set_purecall_handler(previous_pch_);
|
||||
|
||||
if (handler_stack_->back() == this) {
|
||||
handler_stack_->pop_back();
|
||||
@@ -314,6 +312,10 @@ ExceptionHandler::~ExceptionHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ExceptionHandler::RequestUpload(DWORD crash_id) {
|
||||
return crash_generation_client_->RequestUpload(crash_id);
|
||||
}
|
||||
|
||||
// static
|
||||
DWORD ExceptionHandler::ExceptionHandlerThreadMain(void* lpParameter) {
|
||||
ExceptionHandler* self = reinterpret_cast<ExceptionHandler *>(lpParameter);
|
||||
@@ -380,7 +382,7 @@ class AutoExceptionHandler {
|
||||
#if _MSC_VER >= 1400 // MSVC 2005/8
|
||||
_set_invalid_parameter_handler(handler_->previous_iph_);
|
||||
#endif // _MSC_VER >= 1400
|
||||
// _set_purecall_handler(handler_->previous_pch_);
|
||||
_set_purecall_handler(handler_->previous_pch_);
|
||||
}
|
||||
|
||||
~AutoExceptionHandler() {
|
||||
@@ -389,7 +391,7 @@ class AutoExceptionHandler {
|
||||
#if _MSC_VER >= 1400 // MSVC 2005/8
|
||||
_set_invalid_parameter_handler(ExceptionHandler::HandleInvalidParameter);
|
||||
#endif // _MSC_VER >= 1400
|
||||
// _set_purecall_handler(ExceptionHandler::HandlePureVirtualCall);
|
||||
_set_purecall_handler(ExceptionHandler::HandlePureVirtualCall);
|
||||
|
||||
--ExceptionHandler::handler_stack_index_;
|
||||
LeaveCriticalSection(&ExceptionHandler::handler_stack_critical_section_);
|
||||
@@ -498,27 +500,19 @@ void ExceptionHandler::HandleInvalidParameter(const wchar_t* expression,
|
||||
CONTEXT exception_context = {};
|
||||
EXCEPTION_POINTERS exception_ptrs = { &exception_record, &exception_context };
|
||||
|
||||
EXCEPTION_POINTERS* exinfo = NULL;
|
||||
::RtlCaptureContext(&exception_context);
|
||||
|
||||
RtlCaptureContextPtr fnRtlCaptureContext = (RtlCaptureContextPtr)
|
||||
GetProcAddress(GetModuleHandleW(L"kernel32"), "RtlCaptureContext");
|
||||
if (fnRtlCaptureContext) {
|
||||
fnRtlCaptureContext(&exception_context);
|
||||
exception_record.ExceptionCode = STATUS_INVALID_PARAMETER;
|
||||
|
||||
exception_record.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION;
|
||||
|
||||
// We store pointers to the the expression and function strings,
|
||||
// and the line as exception parameters to make them easy to
|
||||
// access by the developer on the far side.
|
||||
exception_record.NumberParameters = 3;
|
||||
exception_record.ExceptionInformation[0] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.expression);
|
||||
exception_record.ExceptionInformation[1] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.file);
|
||||
exception_record.ExceptionInformation[2] = assertion.line;
|
||||
|
||||
exinfo = &exception_ptrs;
|
||||
}
|
||||
// We store pointers to the the expression and function strings,
|
||||
// and the line as exception parameters to make them easy to
|
||||
// access by the developer on the far side.
|
||||
exception_record.NumberParameters = 3;
|
||||
exception_record.ExceptionInformation[0] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.expression);
|
||||
exception_record.ExceptionInformation[1] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.file);
|
||||
exception_record.ExceptionInformation[2] = assertion.line;
|
||||
|
||||
bool success = false;
|
||||
// In case of out-of-process dump generation, directly call
|
||||
@@ -526,10 +520,10 @@ void ExceptionHandler::HandleInvalidParameter(const wchar_t* expression,
|
||||
if (current_handler->IsOutOfProcess()) {
|
||||
success = current_handler->WriteMinidumpWithException(
|
||||
GetCurrentThreadId(),
|
||||
exinfo,
|
||||
&exception_ptrs,
|
||||
&assertion);
|
||||
} else {
|
||||
success = current_handler->WriteMinidumpOnHandlerThread(exinfo,
|
||||
success = current_handler->WriteMinidumpOnHandlerThread(&exception_ptrs,
|
||||
&assertion);
|
||||
}
|
||||
|
||||
@@ -586,27 +580,19 @@ void ExceptionHandler::HandlePureVirtualCall() {
|
||||
CONTEXT exception_context = {};
|
||||
EXCEPTION_POINTERS exception_ptrs = { &exception_record, &exception_context };
|
||||
|
||||
EXCEPTION_POINTERS* exinfo = NULL;
|
||||
::RtlCaptureContext(&exception_context);
|
||||
|
||||
RtlCaptureContextPtr fnRtlCaptureContext = (RtlCaptureContextPtr)
|
||||
GetProcAddress(GetModuleHandleW(L"kernel32"), "RtlCaptureContext");
|
||||
if (fnRtlCaptureContext) {
|
||||
fnRtlCaptureContext(&exception_context);
|
||||
exception_record.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION;
|
||||
|
||||
exception_record.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION;
|
||||
|
||||
// We store pointers to the the expression and function strings,
|
||||
// and the line as exception parameters to make them easy to
|
||||
// access by the developer on the far side.
|
||||
exception_record.NumberParameters = 3;
|
||||
exception_record.ExceptionInformation[0] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.expression);
|
||||
exception_record.ExceptionInformation[1] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.file);
|
||||
exception_record.ExceptionInformation[2] = assertion.line;
|
||||
|
||||
exinfo = &exception_ptrs;
|
||||
}
|
||||
// We store pointers to the the expression and function strings,
|
||||
// and the line as exception parameters to make them easy to
|
||||
// access by the developer on the far side.
|
||||
exception_record.NumberParameters = 3;
|
||||
exception_record.ExceptionInformation[0] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.expression);
|
||||
exception_record.ExceptionInformation[1] =
|
||||
reinterpret_cast<ULONG_PTR>(&assertion.file);
|
||||
exception_record.ExceptionInformation[2] = assertion.line;
|
||||
|
||||
bool success = false;
|
||||
// In case of out-of-process dump generation, directly call
|
||||
@@ -615,10 +601,10 @@ void ExceptionHandler::HandlePureVirtualCall() {
|
||||
if (current_handler->IsOutOfProcess()) {
|
||||
success = current_handler->WriteMinidumpWithException(
|
||||
GetCurrentThreadId(),
|
||||
exinfo,
|
||||
&exception_ptrs,
|
||||
&assertion);
|
||||
} else {
|
||||
success = current_handler->WriteMinidumpOnHandlerThread(exinfo,
|
||||
success = current_handler->WriteMinidumpOnHandlerThread(&exception_ptrs,
|
||||
&assertion);
|
||||
}
|
||||
|
||||
@@ -678,7 +664,18 @@ bool ExceptionHandler::WriteMinidumpOnHandlerThread(
|
||||
}
|
||||
|
||||
bool ExceptionHandler::WriteMinidump() {
|
||||
return WriteMinidumpForException(NULL);
|
||||
// Make up an exception record for the current thread and CPU context
|
||||
// to make it possible for the crash processor to classify these
|
||||
// as do regular crashes, and to make it humane for developers to
|
||||
// analyze them.
|
||||
EXCEPTION_RECORD exception_record = {};
|
||||
CONTEXT exception_context = {};
|
||||
EXCEPTION_POINTERS exception_ptrs = { &exception_record, &exception_context };
|
||||
|
||||
::RtlCaptureContext(&exception_context);
|
||||
exception_record.ExceptionCode = STATUS_NONCONTINUABLE_EXCEPTION;
|
||||
|
||||
return WriteMinidumpForException(&exception_ptrs);
|
||||
}
|
||||
|
||||
bool ExceptionHandler::WriteMinidumpForException(EXCEPTION_POINTERS* exinfo) {
|
||||
@@ -775,7 +772,7 @@ bool ExceptionHandler::WriteMinidumpWithException(
|
||||
if (exinfo) {
|
||||
// Find a memory region of 256 bytes centered on the
|
||||
// faulting instruction pointer.
|
||||
const ULONG64 instruction_pointer =
|
||||
const ULONG64 instruction_pointer =
|
||||
#if defined(_M_IX86)
|
||||
exinfo->ContextRecord->Eip;
|
||||
#elif defined(_M_AMD64)
|
||||
@@ -854,7 +851,7 @@ BOOL CALLBACK ExceptionHandler::MinidumpWriteDumpCallback(
|
||||
callback_context->finished = true;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Include all modules.
|
||||
case IncludeModuleCallback:
|
||||
case ModuleCallback:
|
||||
@@ -866,11 +863,10 @@ BOOL CALLBACK ExceptionHandler::MinidumpWriteDumpCallback(
|
||||
return TRUE;
|
||||
|
||||
// Stop receiving cancel callbacks.
|
||||
//FIXME: CancelCallback is missing in our mingw headers currently, but it's present in trunk, so we need to comment this in as soon as mingw is updated in opensuse (domme)
|
||||
// case CancelCallback:
|
||||
// callback_output->CheckCancel = FALSE;
|
||||
// callback_output->Cancel = FALSE;
|
||||
// return TRUE;
|
||||
case CancelCallback:
|
||||
callback_output->CheckCancel = FALSE;
|
||||
callback_output->Cancel = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
// Ignore other callback types.
|
||||
return FALSE;
|
||||
|
0
thirdparty/breakpad/client/windows/handler/exception_handler.gyp
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/handler/exception_handler.gyp
vendored
Executable file → Normal file
@@ -57,8 +57,8 @@
|
||||
#define CLIENT_WINDOWS_HANDLER_EXCEPTION_HANDLER_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
#include <Windows.h>
|
||||
#include <DbgHelp.h>
|
||||
#include <rpc.h>
|
||||
|
||||
#pragma warning( push )
|
||||
@@ -88,9 +88,9 @@ class ExceptionHandler {
|
||||
// if any.
|
||||
//
|
||||
// If a FilterCallback returns true, Breakpad will continue processing,
|
||||
// attempting to write a minidump. If a FilterCallback returns false, Breakpad
|
||||
// will immediately report the exception as unhandled without writing a
|
||||
// minidump, allowing another handler the opportunity to handle it.
|
||||
// attempting to write a minidump. If a FilterCallback returns false,
|
||||
// Breakpad will immediately report the exception as unhandled without
|
||||
// writing a minidump, allowing another handler the opportunity to handle it.
|
||||
typedef bool (*FilterCallback)(void* context, EXCEPTION_POINTERS* exinfo,
|
||||
MDRawAssertionInfo* assertion);
|
||||
|
||||
@@ -177,6 +177,9 @@ class ExceptionHandler {
|
||||
UpdateNextID(); // Necessary to put dump_path_ in next_minidump_path_.
|
||||
}
|
||||
|
||||
// Requests that a previously reported crash be uploaded.
|
||||
bool RequestUpload(DWORD crash_id);
|
||||
|
||||
// Writes a minidump immediately. This can be used to capture the
|
||||
// execution state independently of a crash. Returns true on success.
|
||||
bool WriteMinidump();
|
||||
|
0
thirdparty/breakpad/client/windows/sender/crash_report_sender.gyp
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/sender/crash_report_sender.gyp
vendored
Executable file → Normal file
@@ -291,6 +291,8 @@ void CrashServerStart() {
|
||||
NULL,
|
||||
ShowClientExited,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
true,
|
||||
&dump_path);
|
||||
|
||||
|
@@ -1,61 +1,61 @@
|
||||
# Copyright (c) 2010, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
{
|
||||
'includes': [
|
||||
'../../build/common.gypi',
|
||||
],
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'crash_generation_app',
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'abstract_class.cc',
|
||||
'abstract_class.h',
|
||||
'crash_generation_app.cc',
|
||||
'crash_generation_app.h',
|
||||
'crash_generation_app.ico',
|
||||
'crash_generation_app.rc',
|
||||
'resource.h',
|
||||
'small.ico',
|
||||
],
|
||||
'dependencies': [
|
||||
'../../breakpad_client.gyp:common',
|
||||
'../../crash_generation/crash_generation.gyp:crash_generation_server',
|
||||
'../../crash_generation/crash_generation.gyp:crash_generation_client',
|
||||
'../../handler/exception_handler.gyp:exception_handler',
|
||||
],
|
||||
'msvs_settings': {
|
||||
'VCLinkerTool': {
|
||||
'SubSystem': '2', # Windows Subsystem as opposed to a console app
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
# Copyright (c) 2010, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
{
|
||||
'includes': [
|
||||
'../../build/common.gypi',
|
||||
],
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'crash_generation_app',
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'abstract_class.cc',
|
||||
'abstract_class.h',
|
||||
'crash_generation_app.cc',
|
||||
'crash_generation_app.h',
|
||||
'crash_generation_app.ico',
|
||||
'crash_generation_app.rc',
|
||||
'resource.h',
|
||||
'small.ico',
|
||||
],
|
||||
'dependencies': [
|
||||
'../../breakpad_client.gyp:common',
|
||||
'../../crash_generation/crash_generation.gyp:crash_generation_server',
|
||||
'../../crash_generation/crash_generation.gyp:crash_generation_client',
|
||||
'../../handler/exception_handler.gyp:exception_handler',
|
||||
],
|
||||
'msvs_settings': {
|
||||
'VCLinkerTool': {
|
||||
'SubSystem': '2', # Windows Subsystem as opposed to a console app
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
0
thirdparty/breakpad/client/windows/unittests/client_tests.gyp
vendored
Executable file → Normal file
0
thirdparty/breakpad/client/windows/unittests/client_tests.gyp
vendored
Executable file → Normal file
@@ -1,298 +1,306 @@
|
||||
// Copyright 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/include/gmock/gmock.h"
|
||||
|
||||
#include "client/windows/crash_generation/crash_generation_server.h"
|
||||
#include "client/windows/common/ipc_protocol.h"
|
||||
|
||||
using testing::_;
|
||||
|
||||
namespace {
|
||||
|
||||
const wchar_t kPipeName[] =
|
||||
L"\\\\.\\pipe\\CrashGenerationServerTest\\TestCaseServer";
|
||||
|
||||
const DWORD kPipeDesiredAccess = FILE_READ_DATA |
|
||||
FILE_WRITE_DATA |
|
||||
FILE_WRITE_ATTRIBUTES;
|
||||
|
||||
const DWORD kPipeFlagsAndAttributes = SECURITY_IDENTIFICATION |
|
||||
SECURITY_SQOS_PRESENT;
|
||||
|
||||
const DWORD kPipeMode = PIPE_READMODE_MESSAGE;
|
||||
|
||||
int kCustomInfoCount = 2;
|
||||
|
||||
google_breakpad::CustomInfoEntry kCustomInfoEntries[] = {
|
||||
google_breakpad::CustomInfoEntry(L"prod", L"CrashGenerationServerTest"),
|
||||
google_breakpad::CustomInfoEntry(L"ver", L"1.0"),
|
||||
};
|
||||
|
||||
class CrashGenerationServerTest : public ::testing::Test {
|
||||
public:
|
||||
CrashGenerationServerTest()
|
||||
: crash_generation_server_(kPipeName,
|
||||
NULL,
|
||||
CallOnClientConnected, &mock_callbacks_,
|
||||
CallOnClientDumpRequested, &mock_callbacks_,
|
||||
CallOnClientExited, &mock_callbacks_,
|
||||
false,
|
||||
NULL),
|
||||
thread_id_(0),
|
||||
exception_pointers_(NULL) {
|
||||
memset(&assert_info_, 0, sizeof(assert_info_));
|
||||
}
|
||||
|
||||
protected:
|
||||
class MockCrashGenerationServerCallbacks {
|
||||
public:
|
||||
MOCK_METHOD1(OnClientConnected,
|
||||
void(const google_breakpad::ClientInfo* client_info));
|
||||
MOCK_METHOD2(OnClientDumpRequested,
|
||||
void(const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path));
|
||||
MOCK_METHOD1(OnClientExited,
|
||||
void(const google_breakpad::ClientInfo* client_info));
|
||||
};
|
||||
|
||||
enum ClientFault {
|
||||
NO_FAULT,
|
||||
CLOSE_AFTER_CONNECT,
|
||||
SEND_INVALID_REGISTRATION,
|
||||
TRUNCATE_REGISTRATION,
|
||||
CLOSE_AFTER_REGISTRATION,
|
||||
RESPONSE_BUFFER_TOO_SMALL,
|
||||
CLOSE_AFTER_RESPONSE,
|
||||
SEND_INVALID_ACK
|
||||
};
|
||||
|
||||
void SetUp() {
|
||||
ASSERT_TRUE(crash_generation_server_.Start());
|
||||
}
|
||||
|
||||
void FaultyClient(ClientFault fault_type) {
|
||||
HANDLE pipe = CreateFile(kPipeName,
|
||||
kPipeDesiredAccess,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
kPipeFlagsAndAttributes,
|
||||
NULL);
|
||||
|
||||
if (pipe == INVALID_HANDLE_VALUE) {
|
||||
ASSERT_EQ(ERROR_PIPE_BUSY, GetLastError());
|
||||
|
||||
// Cannot continue retrying if wait on pipe fails.
|
||||
ASSERT_TRUE(WaitNamedPipe(kPipeName, 500));
|
||||
|
||||
pipe = CreateFile(kPipeName,
|
||||
kPipeDesiredAccess,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
kPipeFlagsAndAttributes,
|
||||
NULL);
|
||||
}
|
||||
|
||||
ASSERT_NE(pipe, INVALID_HANDLE_VALUE);
|
||||
|
||||
DWORD mode = kPipeMode;
|
||||
ASSERT_TRUE(SetNamedPipeHandleState(pipe, &mode, NULL, NULL));
|
||||
|
||||
DoFaultyClient(fault_type, pipe);
|
||||
|
||||
CloseHandle(pipe);
|
||||
}
|
||||
|
||||
void DoTestFault(ClientFault fault) {
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_)).Times(0);
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(fault));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(fault));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(fault));
|
||||
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_));
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(NO_FAULT));
|
||||
|
||||
// Slight hack. The OnClientConnected is only invoked after the ack is
|
||||
// received by the server. At that point, the FaultyClient call has already
|
||||
// returned. The best way to wait until the server is done handling that is
|
||||
// to send one more ping, whose processing will be blocked by delivery of
|
||||
// the OnClientConnected message.
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(CLOSE_AFTER_CONNECT));
|
||||
}
|
||||
|
||||
MockCrashGenerationServerCallbacks mock_callbacks_;
|
||||
|
||||
private:
|
||||
// Depends on the caller to successfully open the pipe before invocation and
|
||||
// to close it immediately afterwards.
|
||||
void DoFaultyClient(ClientFault fault_type, HANDLE pipe) {
|
||||
if (fault_type == CLOSE_AFTER_CONNECT) {
|
||||
return;
|
||||
}
|
||||
|
||||
google_breakpad::CustomClientInfo custom_info = {kCustomInfoEntries,
|
||||
kCustomInfoCount};
|
||||
|
||||
google_breakpad::ProtocolMessage msg(
|
||||
fault_type == SEND_INVALID_REGISTRATION ?
|
||||
google_breakpad::MESSAGE_TAG_NONE :
|
||||
google_breakpad::MESSAGE_TAG_REGISTRATION_REQUEST,
|
||||
GetCurrentProcessId(),
|
||||
MiniDumpNormal,
|
||||
&thread_id_,
|
||||
&exception_pointers_,
|
||||
&assert_info_,
|
||||
custom_info,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
DWORD bytes_count = 0;
|
||||
|
||||
ASSERT_TRUE(WriteFile(pipe,
|
||||
&msg,
|
||||
fault_type == TRUNCATE_REGISTRATION ?
|
||||
sizeof(msg) / 2 : sizeof(msg),
|
||||
&bytes_count,
|
||||
NULL));
|
||||
|
||||
if (fault_type == CLOSE_AFTER_REGISTRATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
google_breakpad::ProtocolMessage reply;
|
||||
|
||||
if (!ReadFile(pipe,
|
||||
&reply,
|
||||
fault_type == RESPONSE_BUFFER_TOO_SMALL ?
|
||||
sizeof(google_breakpad::ProtocolMessage) / 2 :
|
||||
sizeof(google_breakpad::ProtocolMessage),
|
||||
&bytes_count,
|
||||
NULL)) {
|
||||
switch (fault_type) {
|
||||
case TRUNCATE_REGISTRATION:
|
||||
case RESPONSE_BUFFER_TOO_SMALL:
|
||||
case SEND_INVALID_REGISTRATION:
|
||||
return;
|
||||
|
||||
default:
|
||||
FAIL() << "Unexpectedly failed to register.";
|
||||
}
|
||||
}
|
||||
|
||||
if (fault_type == CLOSE_AFTER_RESPONSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
google_breakpad::ProtocolMessage ack_msg;
|
||||
ack_msg.tag = google_breakpad::MESSAGE_TAG_REGISTRATION_ACK;
|
||||
|
||||
ASSERT_TRUE(WriteFile(pipe,
|
||||
&ack_msg,
|
||||
SEND_INVALID_ACK ?
|
||||
sizeof(ack_msg) : sizeof(ack_msg) / 2,
|
||||
&bytes_count,
|
||||
NULL));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CallOnClientConnected(
|
||||
void* context, const google_breakpad::ClientInfo* client_info) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientConnected(client_info);
|
||||
}
|
||||
|
||||
static void CallOnClientDumpRequested(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientDumpRequested(client_info, file_path);
|
||||
}
|
||||
|
||||
static void CallOnClientExited(
|
||||
void* context, const google_breakpad::ClientInfo* client_info) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientExited(client_info);
|
||||
}
|
||||
|
||||
DWORD thread_id_;
|
||||
EXCEPTION_POINTERS* exception_pointers_;
|
||||
MDRawAssertionInfo assert_info_;
|
||||
|
||||
google_breakpad::CrashGenerationServer crash_generation_server_;
|
||||
};
|
||||
|
||||
TEST_F(CrashGenerationServerTest, PingServerTest) {
|
||||
DoTestFault(CLOSE_AFTER_CONNECT);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, InvalidRegistration) {
|
||||
DoTestFault(SEND_INVALID_REGISTRATION);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, TruncateRegistration) {
|
||||
DoTestFault(TRUNCATE_REGISTRATION);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, CloseAfterRegistration) {
|
||||
DoTestFault(CLOSE_AFTER_REGISTRATION);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, ResponseBufferTooSmall) {
|
||||
DoTestFault(RESPONSE_BUFFER_TOO_SMALL);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, CloseAfterResponse) {
|
||||
DoTestFault(CLOSE_AFTER_RESPONSE);
|
||||
}
|
||||
|
||||
// It turns out that, as long as you send one byte, the ACK is accepted and
|
||||
// registration succeeds.
|
||||
TEST_F(CrashGenerationServerTest, SendInvalidAck) {
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(SEND_INVALID_ACK));
|
||||
|
||||
// See DoTestFault for an explanation of this line
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(CLOSE_AFTER_CONNECT));
|
||||
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(NO_FAULT));
|
||||
|
||||
// See DoTestFault for an explanation of this line
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(CLOSE_AFTER_CONNECT));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
// Copyright 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "testing/include/gmock/gmock.h"
|
||||
|
||||
#include "client/windows/crash_generation/crash_generation_server.h"
|
||||
#include "client/windows/common/ipc_protocol.h"
|
||||
|
||||
using testing::_;
|
||||
|
||||
namespace {
|
||||
|
||||
const wchar_t kPipeName[] =
|
||||
L"\\\\.\\pipe\\CrashGenerationServerTest\\TestCaseServer";
|
||||
|
||||
const DWORD kPipeDesiredAccess = FILE_READ_DATA |
|
||||
FILE_WRITE_DATA |
|
||||
FILE_WRITE_ATTRIBUTES;
|
||||
|
||||
const DWORD kPipeFlagsAndAttributes = SECURITY_IDENTIFICATION |
|
||||
SECURITY_SQOS_PRESENT;
|
||||
|
||||
const DWORD kPipeMode = PIPE_READMODE_MESSAGE;
|
||||
|
||||
int kCustomInfoCount = 2;
|
||||
|
||||
google_breakpad::CustomInfoEntry kCustomInfoEntries[] = {
|
||||
google_breakpad::CustomInfoEntry(L"prod", L"CrashGenerationServerTest"),
|
||||
google_breakpad::CustomInfoEntry(L"ver", L"1.0"),
|
||||
};
|
||||
|
||||
class CrashGenerationServerTest : public ::testing::Test {
|
||||
public:
|
||||
CrashGenerationServerTest()
|
||||
: crash_generation_server_(kPipeName,
|
||||
NULL,
|
||||
CallOnClientConnected, &mock_callbacks_,
|
||||
CallOnClientDumpRequested, &mock_callbacks_,
|
||||
CallOnClientExited, &mock_callbacks_,
|
||||
CallOnClientUploadRequested, &mock_callbacks_,
|
||||
false,
|
||||
NULL),
|
||||
thread_id_(0),
|
||||
exception_pointers_(NULL) {
|
||||
memset(&assert_info_, 0, sizeof(assert_info_));
|
||||
}
|
||||
|
||||
protected:
|
||||
class MockCrashGenerationServerCallbacks {
|
||||
public:
|
||||
MOCK_METHOD1(OnClientConnected,
|
||||
void(const google_breakpad::ClientInfo* client_info));
|
||||
MOCK_METHOD2(OnClientDumpRequested,
|
||||
void(const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path));
|
||||
MOCK_METHOD1(OnClientExited,
|
||||
void(const google_breakpad::ClientInfo* client_info));
|
||||
MOCK_METHOD1(OnClientUploadRequested,
|
||||
void(const DWORD crash_id));
|
||||
};
|
||||
|
||||
enum ClientFault {
|
||||
NO_FAULT,
|
||||
CLOSE_AFTER_CONNECT,
|
||||
SEND_INVALID_REGISTRATION,
|
||||
TRUNCATE_REGISTRATION,
|
||||
CLOSE_AFTER_REGISTRATION,
|
||||
RESPONSE_BUFFER_TOO_SMALL,
|
||||
CLOSE_AFTER_RESPONSE,
|
||||
SEND_INVALID_ACK
|
||||
};
|
||||
|
||||
void SetUp() {
|
||||
ASSERT_TRUE(crash_generation_server_.Start());
|
||||
}
|
||||
|
||||
void FaultyClient(ClientFault fault_type) {
|
||||
HANDLE pipe = CreateFile(kPipeName,
|
||||
kPipeDesiredAccess,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
kPipeFlagsAndAttributes,
|
||||
NULL);
|
||||
|
||||
if (pipe == INVALID_HANDLE_VALUE) {
|
||||
ASSERT_EQ(ERROR_PIPE_BUSY, GetLastError());
|
||||
|
||||
// Cannot continue retrying if wait on pipe fails.
|
||||
ASSERT_TRUE(WaitNamedPipe(kPipeName, 500));
|
||||
|
||||
pipe = CreateFile(kPipeName,
|
||||
kPipeDesiredAccess,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
kPipeFlagsAndAttributes,
|
||||
NULL);
|
||||
}
|
||||
|
||||
ASSERT_NE(pipe, INVALID_HANDLE_VALUE);
|
||||
|
||||
DWORD mode = kPipeMode;
|
||||
ASSERT_TRUE(SetNamedPipeHandleState(pipe, &mode, NULL, NULL));
|
||||
|
||||
DoFaultyClient(fault_type, pipe);
|
||||
|
||||
CloseHandle(pipe);
|
||||
}
|
||||
|
||||
void DoTestFault(ClientFault fault) {
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_)).Times(0);
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(fault));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(fault));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(fault));
|
||||
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_));
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(NO_FAULT));
|
||||
|
||||
// Slight hack. The OnClientConnected is only invoked after the ack is
|
||||
// received by the server. At that point, the FaultyClient call has already
|
||||
// returned. The best way to wait until the server is done handling that is
|
||||
// to send one more ping, whose processing will be blocked by delivery of
|
||||
// the OnClientConnected message.
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(CLOSE_AFTER_CONNECT));
|
||||
}
|
||||
|
||||
MockCrashGenerationServerCallbacks mock_callbacks_;
|
||||
|
||||
private:
|
||||
// Depends on the caller to successfully open the pipe before invocation and
|
||||
// to close it immediately afterwards.
|
||||
void DoFaultyClient(ClientFault fault_type, HANDLE pipe) {
|
||||
if (fault_type == CLOSE_AFTER_CONNECT) {
|
||||
return;
|
||||
}
|
||||
|
||||
google_breakpad::CustomClientInfo custom_info = {kCustomInfoEntries,
|
||||
kCustomInfoCount};
|
||||
|
||||
google_breakpad::ProtocolMessage msg(
|
||||
fault_type == SEND_INVALID_REGISTRATION ?
|
||||
google_breakpad::MESSAGE_TAG_NONE :
|
||||
google_breakpad::MESSAGE_TAG_REGISTRATION_REQUEST,
|
||||
GetCurrentProcessId(),
|
||||
MiniDumpNormal,
|
||||
&thread_id_,
|
||||
&exception_pointers_,
|
||||
&assert_info_,
|
||||
custom_info,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
DWORD bytes_count = 0;
|
||||
|
||||
ASSERT_TRUE(WriteFile(pipe,
|
||||
&msg,
|
||||
fault_type == TRUNCATE_REGISTRATION ?
|
||||
sizeof(msg) / 2 : sizeof(msg),
|
||||
&bytes_count,
|
||||
NULL));
|
||||
|
||||
if (fault_type == CLOSE_AFTER_REGISTRATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
google_breakpad::ProtocolMessage reply;
|
||||
|
||||
if (!ReadFile(pipe,
|
||||
&reply,
|
||||
fault_type == RESPONSE_BUFFER_TOO_SMALL ?
|
||||
sizeof(google_breakpad::ProtocolMessage) / 2 :
|
||||
sizeof(google_breakpad::ProtocolMessage),
|
||||
&bytes_count,
|
||||
NULL)) {
|
||||
switch (fault_type) {
|
||||
case TRUNCATE_REGISTRATION:
|
||||
case RESPONSE_BUFFER_TOO_SMALL:
|
||||
case SEND_INVALID_REGISTRATION:
|
||||
return;
|
||||
|
||||
default:
|
||||
FAIL() << "Unexpectedly failed to register.";
|
||||
}
|
||||
}
|
||||
|
||||
if (fault_type == CLOSE_AFTER_RESPONSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
google_breakpad::ProtocolMessage ack_msg;
|
||||
ack_msg.tag = google_breakpad::MESSAGE_TAG_REGISTRATION_ACK;
|
||||
|
||||
ASSERT_TRUE(WriteFile(pipe,
|
||||
&ack_msg,
|
||||
SEND_INVALID_ACK ?
|
||||
sizeof(ack_msg) : sizeof(ack_msg) / 2,
|
||||
&bytes_count,
|
||||
NULL));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CallOnClientConnected(
|
||||
void* context, const google_breakpad::ClientInfo* client_info) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientConnected(client_info);
|
||||
}
|
||||
|
||||
static void CallOnClientDumpRequested(
|
||||
void* context,
|
||||
const google_breakpad::ClientInfo* client_info,
|
||||
const std::wstring* file_path) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientDumpRequested(client_info, file_path);
|
||||
}
|
||||
|
||||
static void CallOnClientExited(
|
||||
void* context, const google_breakpad::ClientInfo* client_info) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientExited(client_info);
|
||||
}
|
||||
|
||||
static void CallOnClientUploadRequested(void* context, const DWORD crash_id) {
|
||||
static_cast<MockCrashGenerationServerCallbacks*>(context)->
|
||||
OnClientUploadRequested(crash_id);
|
||||
}
|
||||
|
||||
DWORD thread_id_;
|
||||
EXCEPTION_POINTERS* exception_pointers_;
|
||||
MDRawAssertionInfo assert_info_;
|
||||
|
||||
google_breakpad::CrashGenerationServer crash_generation_server_;
|
||||
};
|
||||
|
||||
TEST_F(CrashGenerationServerTest, PingServerTest) {
|
||||
DoTestFault(CLOSE_AFTER_CONNECT);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, InvalidRegistration) {
|
||||
DoTestFault(SEND_INVALID_REGISTRATION);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, TruncateRegistration) {
|
||||
DoTestFault(TRUNCATE_REGISTRATION);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, CloseAfterRegistration) {
|
||||
DoTestFault(CLOSE_AFTER_REGISTRATION);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, ResponseBufferTooSmall) {
|
||||
DoTestFault(RESPONSE_BUFFER_TOO_SMALL);
|
||||
}
|
||||
|
||||
TEST_F(CrashGenerationServerTest, CloseAfterResponse) {
|
||||
DoTestFault(CLOSE_AFTER_RESPONSE);
|
||||
}
|
||||
|
||||
// It turns out that, as long as you send one byte, the ACK is accepted and
|
||||
// registration succeeds.
|
||||
TEST_F(CrashGenerationServerTest, SendInvalidAck) {
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(SEND_INVALID_ACK));
|
||||
|
||||
// See DoTestFault for an explanation of this line
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(CLOSE_AFTER_CONNECT));
|
||||
|
||||
EXPECT_CALL(mock_callbacks_, OnClientConnected(_));
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(NO_FAULT));
|
||||
|
||||
// See DoTestFault for an explanation of this line
|
||||
ASSERT_NO_FATAL_FAILURE(FaultyClient(CLOSE_AFTER_CONNECT));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
368
thirdparty/breakpad/client/windows/unittests/dump_analysis.cc
vendored
Executable file → Normal file
368
thirdparty/breakpad/client/windows/unittests/dump_analysis.cc
vendored
Executable file → Normal file
@@ -1,184 +1,184 @@
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#include "dump_analysis.h" // NOLINT
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
DumpAnalysis::~DumpAnalysis() {
|
||||
if (dump_file_view_ != NULL) {
|
||||
EXPECT_TRUE(::UnmapViewOfFile(dump_file_view_));
|
||||
::CloseHandle(dump_file_mapping_);
|
||||
dump_file_mapping_ = NULL;
|
||||
}
|
||||
|
||||
if (dump_file_handle_ != NULL) {
|
||||
::CloseHandle(dump_file_handle_);
|
||||
dump_file_handle_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void DumpAnalysis::EnsureDumpMapped() {
|
||||
if (dump_file_view_ == NULL) {
|
||||
dump_file_handle_ = ::CreateFile(dump_file_.c_str(),
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
NULL);
|
||||
ASSERT_TRUE(dump_file_handle_ != NULL);
|
||||
ASSERT_TRUE(dump_file_mapping_ == NULL);
|
||||
|
||||
dump_file_mapping_ = ::CreateFileMapping(dump_file_handle_,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
0,
|
||||
0,
|
||||
NULL);
|
||||
ASSERT_TRUE(dump_file_mapping_ != NULL);
|
||||
|
||||
dump_file_view_ = ::MapViewOfFile(dump_file_mapping_,
|
||||
FILE_MAP_READ,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
ASSERT_TRUE(dump_file_view_ != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasTebs() const {
|
||||
MINIDUMP_THREAD_LIST* thread_list = NULL;
|
||||
size_t thread_list_size = GetStream(ThreadListStream, &thread_list);
|
||||
|
||||
if (thread_list_size > 0 && thread_list != NULL) {
|
||||
for (ULONG i = 0; i < thread_list->NumberOfThreads; ++i) {
|
||||
if (!HasMemory(thread_list->Threads[i].Teb))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// No thread list, no TEB info.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasPeb() const {
|
||||
MINIDUMP_THREAD_LIST* thread_list = NULL;
|
||||
size_t thread_list_size = GetStream(ThreadListStream, &thread_list);
|
||||
|
||||
if (thread_list_size > 0 && thread_list != NULL &&
|
||||
thread_list->NumberOfThreads > 0) {
|
||||
FakeTEB* teb = NULL;
|
||||
if (!HasMemory(thread_list->Threads[0].Teb, &teb))
|
||||
return false;
|
||||
|
||||
return HasMemory(teb->peb);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasStream(ULONG stream_number) const {
|
||||
void* stream = NULL;
|
||||
size_t stream_size = GetStreamImpl(stream_number, &stream);
|
||||
return stream_size > 0 && stream != NULL;
|
||||
}
|
||||
|
||||
size_t DumpAnalysis::GetStreamImpl(ULONG stream_number, void** stream) const {
|
||||
MINIDUMP_DIRECTORY* directory = NULL;
|
||||
ULONG memory_list_size = 0;
|
||||
BOOL ret = ::MiniDumpReadDumpStream(dump_file_view_,
|
||||
stream_number,
|
||||
&directory,
|
||||
stream,
|
||||
&memory_list_size);
|
||||
|
||||
return ret ? memory_list_size : 0;
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasMemoryImpl(const void *addr_in, size_t structuresize,
|
||||
void **structure) const {
|
||||
uintptr_t address = reinterpret_cast<uintptr_t>(addr_in);
|
||||
MINIDUMP_MEMORY_LIST* memory_list = NULL;
|
||||
size_t memory_list_size = GetStream(MemoryListStream, &memory_list);
|
||||
if (memory_list_size > 0 && memory_list != NULL) {
|
||||
for (ULONG i = 0; i < memory_list->NumberOfMemoryRanges; ++i) {
|
||||
MINIDUMP_MEMORY_DESCRIPTOR& descr = memory_list->MemoryRanges[i];
|
||||
const uintptr_t range_start =
|
||||
static_cast<uintptr_t>(descr.StartOfMemoryRange);
|
||||
uintptr_t range_end = range_start + descr.Memory.DataSize;
|
||||
|
||||
if (address >= range_start &&
|
||||
address + structuresize < range_end) {
|
||||
// The start address falls in the range, and the end address is
|
||||
// in bounds, return a pointer to the structure if requested.
|
||||
if (structure != NULL)
|
||||
*structure = RVA_TO_ADDR(dump_file_view_, descr.Memory.Rva);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We didn't find the range in a MINIDUMP_MEMORY_LIST, so maybe this
|
||||
// is a full dump using MINIDUMP_MEMORY64_LIST with all the memory at the
|
||||
// end of the dump file.
|
||||
MINIDUMP_MEMORY64_LIST* memory64_list = NULL;
|
||||
memory_list_size = GetStream(Memory64ListStream, &memory64_list);
|
||||
if (memory_list_size > 0 && memory64_list != NULL) {
|
||||
// Keep track of where the current descriptor maps to.
|
||||
RVA64 curr_rva = memory64_list->BaseRva;
|
||||
for (ULONG i = 0; i < memory64_list->NumberOfMemoryRanges; ++i) {
|
||||
MINIDUMP_MEMORY_DESCRIPTOR64& descr = memory64_list->MemoryRanges[i];
|
||||
uintptr_t range_start =
|
||||
static_cast<uintptr_t>(descr.StartOfMemoryRange);
|
||||
uintptr_t range_end = range_start + static_cast<size_t>(descr.DataSize);
|
||||
|
||||
if (address >= range_start &&
|
||||
address + structuresize < range_end) {
|
||||
// The start address falls in the range, and the end address is
|
||||
// in bounds, return a pointer to the structure if requested.
|
||||
if (structure != NULL)
|
||||
*structure = RVA_TO_ADDR(dump_file_view_, curr_rva);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Advance the current RVA.
|
||||
curr_rva += descr.DataSize;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#include "dump_analysis.h" // NOLINT
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
DumpAnalysis::~DumpAnalysis() {
|
||||
if (dump_file_view_ != NULL) {
|
||||
EXPECT_TRUE(::UnmapViewOfFile(dump_file_view_));
|
||||
::CloseHandle(dump_file_mapping_);
|
||||
dump_file_mapping_ = NULL;
|
||||
}
|
||||
|
||||
if (dump_file_handle_ != NULL) {
|
||||
::CloseHandle(dump_file_handle_);
|
||||
dump_file_handle_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void DumpAnalysis::EnsureDumpMapped() {
|
||||
if (dump_file_view_ == NULL) {
|
||||
dump_file_handle_ = ::CreateFile(dump_file_.c_str(),
|
||||
GENERIC_READ,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
NULL);
|
||||
ASSERT_TRUE(dump_file_handle_ != NULL);
|
||||
ASSERT_TRUE(dump_file_mapping_ == NULL);
|
||||
|
||||
dump_file_mapping_ = ::CreateFileMapping(dump_file_handle_,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
0,
|
||||
0,
|
||||
NULL);
|
||||
ASSERT_TRUE(dump_file_mapping_ != NULL);
|
||||
|
||||
dump_file_view_ = ::MapViewOfFile(dump_file_mapping_,
|
||||
FILE_MAP_READ,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
ASSERT_TRUE(dump_file_view_ != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasTebs() const {
|
||||
MINIDUMP_THREAD_LIST* thread_list = NULL;
|
||||
size_t thread_list_size = GetStream(ThreadListStream, &thread_list);
|
||||
|
||||
if (thread_list_size > 0 && thread_list != NULL) {
|
||||
for (ULONG i = 0; i < thread_list->NumberOfThreads; ++i) {
|
||||
if (!HasMemory(thread_list->Threads[i].Teb))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// No thread list, no TEB info.
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasPeb() const {
|
||||
MINIDUMP_THREAD_LIST* thread_list = NULL;
|
||||
size_t thread_list_size = GetStream(ThreadListStream, &thread_list);
|
||||
|
||||
if (thread_list_size > 0 && thread_list != NULL &&
|
||||
thread_list->NumberOfThreads > 0) {
|
||||
FakeTEB* teb = NULL;
|
||||
if (!HasMemory(thread_list->Threads[0].Teb, &teb))
|
||||
return false;
|
||||
|
||||
return HasMemory(teb->peb);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasStream(ULONG stream_number) const {
|
||||
void* stream = NULL;
|
||||
size_t stream_size = GetStreamImpl(stream_number, &stream);
|
||||
return stream_size > 0 && stream != NULL;
|
||||
}
|
||||
|
||||
size_t DumpAnalysis::GetStreamImpl(ULONG stream_number, void** stream) const {
|
||||
MINIDUMP_DIRECTORY* directory = NULL;
|
||||
ULONG memory_list_size = 0;
|
||||
BOOL ret = ::MiniDumpReadDumpStream(dump_file_view_,
|
||||
stream_number,
|
||||
&directory,
|
||||
stream,
|
||||
&memory_list_size);
|
||||
|
||||
return ret ? memory_list_size : 0;
|
||||
}
|
||||
|
||||
bool DumpAnalysis::HasMemoryImpl(const void *addr_in, size_t structuresize,
|
||||
void **structure) const {
|
||||
uintptr_t address = reinterpret_cast<uintptr_t>(addr_in);
|
||||
MINIDUMP_MEMORY_LIST* memory_list = NULL;
|
||||
size_t memory_list_size = GetStream(MemoryListStream, &memory_list);
|
||||
if (memory_list_size > 0 && memory_list != NULL) {
|
||||
for (ULONG i = 0; i < memory_list->NumberOfMemoryRanges; ++i) {
|
||||
MINIDUMP_MEMORY_DESCRIPTOR& descr = memory_list->MemoryRanges[i];
|
||||
const uintptr_t range_start =
|
||||
static_cast<uintptr_t>(descr.StartOfMemoryRange);
|
||||
uintptr_t range_end = range_start + descr.Memory.DataSize;
|
||||
|
||||
if (address >= range_start &&
|
||||
address + structuresize < range_end) {
|
||||
// The start address falls in the range, and the end address is
|
||||
// in bounds, return a pointer to the structure if requested.
|
||||
if (structure != NULL)
|
||||
*structure = RVA_TO_ADDR(dump_file_view_, descr.Memory.Rva);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We didn't find the range in a MINIDUMP_MEMORY_LIST, so maybe this
|
||||
// is a full dump using MINIDUMP_MEMORY64_LIST with all the memory at the
|
||||
// end of the dump file.
|
||||
MINIDUMP_MEMORY64_LIST* memory64_list = NULL;
|
||||
memory_list_size = GetStream(Memory64ListStream, &memory64_list);
|
||||
if (memory_list_size > 0 && memory64_list != NULL) {
|
||||
// Keep track of where the current descriptor maps to.
|
||||
RVA64 curr_rva = memory64_list->BaseRva;
|
||||
for (ULONG i = 0; i < memory64_list->NumberOfMemoryRanges; ++i) {
|
||||
MINIDUMP_MEMORY_DESCRIPTOR64& descr = memory64_list->MemoryRanges[i];
|
||||
uintptr_t range_start =
|
||||
static_cast<uintptr_t>(descr.StartOfMemoryRange);
|
||||
uintptr_t range_end = range_start + static_cast<size_t>(descr.DataSize);
|
||||
|
||||
if (address >= range_start &&
|
||||
address + structuresize < range_end) {
|
||||
// The start address falls in the range, and the end address is
|
||||
// in bounds, return a pointer to the structure if requested.
|
||||
if (structure != NULL)
|
||||
*structure = RVA_TO_ADDR(dump_file_view_, curr_rva);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Advance the current RVA.
|
||||
curr_rva += descr.DataSize;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
204
thirdparty/breakpad/client/windows/unittests/dump_analysis.h
vendored
Executable file → Normal file
204
thirdparty/breakpad/client/windows/unittests/dump_analysis.h
vendored
Executable file → Normal file
@@ -1,102 +1,102 @@
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
|
||||
#define CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
|
||||
|
||||
#include "../crash_generation/minidump_generator.h"
|
||||
|
||||
// Convenience to get to the PEB pointer in a TEB.
|
||||
struct FakeTEB {
|
||||
char dummy[0x30];
|
||||
void* peb;
|
||||
};
|
||||
|
||||
class DumpAnalysis {
|
||||
public:
|
||||
explicit DumpAnalysis(const std::wstring& file_path)
|
||||
: dump_file_(file_path), dump_file_view_(NULL), dump_file_mapping_(NULL),
|
||||
dump_file_handle_(NULL) {
|
||||
EnsureDumpMapped();
|
||||
}
|
||||
~DumpAnalysis();
|
||||
|
||||
bool HasStream(ULONG stream_number) const;
|
||||
|
||||
// This is template to keep type safety in the front, but we end up casting
|
||||
// to void** inside the implementation to pass the pointer to Win32. So
|
||||
// casting here is considered safe.
|
||||
template <class StreamType>
|
||||
size_t GetStream(ULONG stream_number, StreamType** stream) const {
|
||||
return GetStreamImpl(stream_number, reinterpret_cast<void**>(stream));
|
||||
}
|
||||
|
||||
bool HasTebs() const;
|
||||
bool HasPeb() const;
|
||||
bool HasMemory(ULONG64 address) const {
|
||||
return HasMemory<BYTE>(address, NULL);
|
||||
}
|
||||
|
||||
bool HasMemory(const void* address) const {
|
||||
return HasMemory<BYTE>(address, NULL);
|
||||
}
|
||||
|
||||
template <class StructureType>
|
||||
bool HasMemory(ULONG64 address, StructureType** structure = NULL) const {
|
||||
// We can't cope with 64 bit addresses for now.
|
||||
if (address > 0xFFFFFFFFUL)
|
||||
return false;
|
||||
|
||||
return HasMemory(reinterpret_cast<void*>(address), structure);
|
||||
}
|
||||
|
||||
template <class StructureType>
|
||||
bool HasMemory(const void* addr_in, StructureType** structure = NULL) const {
|
||||
return HasMemoryImpl(addr_in, sizeof(StructureType),
|
||||
reinterpret_cast<void**>(structure));
|
||||
}
|
||||
|
||||
protected:
|
||||
void EnsureDumpMapped();
|
||||
|
||||
HANDLE dump_file_mapping_;
|
||||
HANDLE dump_file_handle_;
|
||||
void* dump_file_view_;
|
||||
std::wstring dump_file_;
|
||||
|
||||
private:
|
||||
// This is the implementation of GetStream<>.
|
||||
size_t GetStreamImpl(ULONG stream_number, void** stream) const;
|
||||
|
||||
// This is the implementation of HasMemory<>.
|
||||
bool HasMemoryImpl(const void* addr_in, size_t pointersize,
|
||||
void** structure) const;
|
||||
};
|
||||
|
||||
#endif // CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
|
||||
#define CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
|
||||
|
||||
#include "../crash_generation/minidump_generator.h"
|
||||
|
||||
// Convenience to get to the PEB pointer in a TEB.
|
||||
struct FakeTEB {
|
||||
char dummy[0x30];
|
||||
void* peb;
|
||||
};
|
||||
|
||||
class DumpAnalysis {
|
||||
public:
|
||||
explicit DumpAnalysis(const std::wstring& file_path)
|
||||
: dump_file_(file_path), dump_file_view_(NULL), dump_file_mapping_(NULL),
|
||||
dump_file_handle_(NULL) {
|
||||
EnsureDumpMapped();
|
||||
}
|
||||
~DumpAnalysis();
|
||||
|
||||
bool HasStream(ULONG stream_number) const;
|
||||
|
||||
// This is template to keep type safety in the front, but we end up casting
|
||||
// to void** inside the implementation to pass the pointer to Win32. So
|
||||
// casting here is considered safe.
|
||||
template <class StreamType>
|
||||
size_t GetStream(ULONG stream_number, StreamType** stream) const {
|
||||
return GetStreamImpl(stream_number, reinterpret_cast<void**>(stream));
|
||||
}
|
||||
|
||||
bool HasTebs() const;
|
||||
bool HasPeb() const;
|
||||
bool HasMemory(ULONG64 address) const {
|
||||
return HasMemory<BYTE>(address, NULL);
|
||||
}
|
||||
|
||||
bool HasMemory(const void* address) const {
|
||||
return HasMemory<BYTE>(address, NULL);
|
||||
}
|
||||
|
||||
template <class StructureType>
|
||||
bool HasMemory(ULONG64 address, StructureType** structure = NULL) const {
|
||||
// We can't cope with 64 bit addresses for now.
|
||||
if (address > 0xFFFFFFFFUL)
|
||||
return false;
|
||||
|
||||
return HasMemory(reinterpret_cast<void*>(address), structure);
|
||||
}
|
||||
|
||||
template <class StructureType>
|
||||
bool HasMemory(const void* addr_in, StructureType** structure = NULL) const {
|
||||
return HasMemoryImpl(addr_in, sizeof(StructureType),
|
||||
reinterpret_cast<void**>(structure));
|
||||
}
|
||||
|
||||
protected:
|
||||
void EnsureDumpMapped();
|
||||
|
||||
HANDLE dump_file_mapping_;
|
||||
HANDLE dump_file_handle_;
|
||||
void* dump_file_view_;
|
||||
std::wstring dump_file_;
|
||||
|
||||
private:
|
||||
// This is the implementation of GetStream<>.
|
||||
size_t GetStreamImpl(ULONG stream_number, void** stream) const;
|
||||
|
||||
// This is the implementation of HasMemory<>.
|
||||
bool HasMemoryImpl(const void* addr_in, size_t pointersize,
|
||||
void** structure) const;
|
||||
};
|
||||
|
||||
#endif // CLIENT_WINDOWS_UNITTESTS_DUMP_ANALYSIS_H_
|
||||
|
4
thirdparty/breakpad/client/windows/unittests/exception_handler_death_test.cc
vendored
Executable file → Normal file
4
thirdparty/breakpad/client/windows/unittests/exception_handler_death_test.cc
vendored
Executable file → Normal file
@@ -161,8 +161,8 @@ TEST_F(ExceptionHandlerDeathTest, OutOfProcTest) {
|
||||
ASSERT_TRUE(DoesPathExist(temp_path_));
|
||||
std::wstring dump_path(temp_path_);
|
||||
google_breakpad::CrashGenerationServer server(
|
||||
kPipeName, NULL, NULL, NULL, &clientDumpCallback, NULL, NULL, NULL, true,
|
||||
&dump_path);
|
||||
kPipeName, NULL, NULL, NULL, &clientDumpCallback, NULL, NULL, NULL, NULL,
|
||||
NULL, true, &dump_path);
|
||||
|
||||
// This HAS to be EXPECT_, because when this test case is executed in the
|
||||
// child process, the server registration will fail due to the named pipe
|
||||
|
8
thirdparty/breakpad/client/windows/unittests/exception_handler_test.cc
vendored
Executable file → Normal file
8
thirdparty/breakpad/client/windows/unittests/exception_handler_test.cc
vendored
Executable file → Normal file
@@ -220,8 +220,8 @@ TEST_F(ExceptionHandlerTest, InvalidParameterMiniDumpTest) {
|
||||
ASSERT_TRUE(DoesPathExist(temp_path_));
|
||||
wstring dump_path(temp_path_);
|
||||
google_breakpad::CrashGenerationServer server(
|
||||
kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true,
|
||||
&dump_path);
|
||||
kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, NULL,
|
||||
NULL, true, &dump_path);
|
||||
|
||||
ASSERT_TRUE(dump_file.empty() && full_dump_file.empty());
|
||||
|
||||
@@ -291,8 +291,8 @@ TEST_F(ExceptionHandlerTest, PureVirtualCallMiniDumpTest) {
|
||||
ASSERT_TRUE(DoesPathExist(temp_path_));
|
||||
wstring dump_path(temp_path_);
|
||||
google_breakpad::CrashGenerationServer server(
|
||||
kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, true,
|
||||
&dump_path);
|
||||
kPipeName, NULL, NULL, NULL, ClientDumpCallback, NULL, NULL, NULL, NULL,
|
||||
NULL, true, &dump_path);
|
||||
|
||||
ASSERT_TRUE(dump_file.empty() && full_dump_file.empty());
|
||||
|
||||
|
664
thirdparty/breakpad/client/windows/unittests/minidump_test.cc
vendored
Executable file → Normal file
664
thirdparty/breakpad/client/windows/unittests/minidump_test.cc
vendored
Executable file → Normal file
@@ -1,332 +1,332 @@
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#include "../crash_generation/minidump_generator.h"
|
||||
#include "dump_analysis.h" // NOLINT
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Minidump with stacks, PEB, TEB, and unloaded module list.
|
||||
const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
||||
|
||||
// Minidump with all of the above, plus memory referenced from stack.
|
||||
const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithUnloadedModules | // Get unloaded modules when available.
|
||||
MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.
|
||||
|
||||
// Large dump with all process memory.
|
||||
const MINIDUMP_TYPE kFullDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithFullMemory | // Full memory from process.
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithHandleData | // Get all handle information.
|
||||
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
||||
|
||||
class MinidumpTest: public testing::Test {
|
||||
public:
|
||||
MinidumpTest() {
|
||||
wchar_t temp_dir_path[ MAX_PATH ] = {0};
|
||||
::GetTempPath(MAX_PATH, temp_dir_path);
|
||||
dump_path_ = temp_dir_path;
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
// Make sure URLMon isn't loaded into our process.
|
||||
ASSERT_EQ(NULL, ::GetModuleHandle(L"urlmon.dll"));
|
||||
|
||||
// Then load and unload it to ensure we have something to
|
||||
// stock the unloaded module list with.
|
||||
HMODULE urlmon = ::LoadLibrary(L"urlmon.dll");
|
||||
ASSERT_TRUE(urlmon != NULL);
|
||||
ASSERT_TRUE(::FreeLibrary(urlmon));
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
if (!dump_file_.empty()) {
|
||||
::DeleteFile(dump_file_.c_str());
|
||||
dump_file_ = L"";
|
||||
}
|
||||
if (!full_dump_file_.empty()) {
|
||||
::DeleteFile(full_dump_file_.c_str());
|
||||
full_dump_file_ = L"";
|
||||
}
|
||||
}
|
||||
|
||||
bool WriteDump(ULONG flags) {
|
||||
using google_breakpad::MinidumpGenerator;
|
||||
|
||||
// Fake exception is access violation on write to this.
|
||||
EXCEPTION_RECORD ex_record = {
|
||||
STATUS_ACCESS_VIOLATION, // ExceptionCode
|
||||
0, // ExceptionFlags
|
||||
NULL, // ExceptionRecord;
|
||||
reinterpret_cast<void*>(0xCAFEBABE), // ExceptionAddress;
|
||||
2, // NumberParameters;
|
||||
{ EXCEPTION_WRITE_FAULT, reinterpret_cast<ULONG_PTR>(this) }
|
||||
};
|
||||
CONTEXT ctx_record = {};
|
||||
EXCEPTION_POINTERS ex_ptrs = {
|
||||
&ex_record,
|
||||
&ctx_record,
|
||||
};
|
||||
|
||||
MinidumpGenerator generator(dump_path_);
|
||||
|
||||
// And write a dump
|
||||
bool result = generator.WriteMinidump(::GetCurrentProcess(),
|
||||
::GetCurrentProcessId(),
|
||||
::GetCurrentThreadId(),
|
||||
::GetCurrentThreadId(),
|
||||
&ex_ptrs,
|
||||
NULL,
|
||||
static_cast<MINIDUMP_TYPE>(flags),
|
||||
TRUE,
|
||||
&dump_file_,
|
||||
&full_dump_file_);
|
||||
return result == TRUE;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::wstring dump_file_;
|
||||
std::wstring full_dump_file_;
|
||||
|
||||
std::wstring dump_path_;
|
||||
};
|
||||
|
||||
// We need to be able to get file information from Windows
|
||||
bool HasFileInfo(const std::wstring& file_path) {
|
||||
DWORD dummy;
|
||||
const wchar_t* path = file_path.c_str();
|
||||
DWORD length = ::GetFileVersionInfoSize(path, &dummy);
|
||||
if (length == 0)
|
||||
return NULL;
|
||||
|
||||
void* data = calloc(length, 1);
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
if (!::GetFileVersionInfo(path, dummy, length, data)) {
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
void* translate = NULL;
|
||||
UINT page_count;
|
||||
BOOL query_result = VerQueryValue(
|
||||
data,
|
||||
L"\\VarFileInfo\\Translation",
|
||||
static_cast<void**>(&translate),
|
||||
&page_count);
|
||||
|
||||
free(data);
|
||||
if (query_result && translate) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, Version) {
|
||||
API_VERSION* version = ::ImagehlpApiVersion();
|
||||
|
||||
HMODULE dbg_help = ::GetModuleHandle(L"dbghelp.dll");
|
||||
ASSERT_TRUE(dbg_help != NULL);
|
||||
|
||||
wchar_t dbg_help_file[1024] = {};
|
||||
ASSERT_TRUE(::GetModuleFileName(dbg_help,
|
||||
dbg_help_file,
|
||||
sizeof(dbg_help_file) /
|
||||
sizeof(*dbg_help_file)));
|
||||
ASSERT_TRUE(HasFileInfo(std::wstring(dbg_help_file)) != NULL);
|
||||
|
||||
// LOG(INFO) << "DbgHelp.dll version: " << file_info->file_version();
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, Normal) {
|
||||
EXPECT_TRUE(WriteDump(MiniDumpNormal));
|
||||
DumpAnalysis mini(dump_file_);
|
||||
|
||||
// We expect threads, modules and some memory.
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
|
||||
// We expect no PEB nor TEBs in this dump.
|
||||
EXPECT_FALSE(mini.HasTebs());
|
||||
EXPECT_FALSE(mini.HasPeb());
|
||||
|
||||
// We expect no off-stack memory in this dump.
|
||||
EXPECT_FALSE(mini.HasMemory(this));
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, SmallDump) {
|
||||
ASSERT_TRUE(WriteDump(kSmallDumpType));
|
||||
DumpAnalysis mini(dump_file_);
|
||||
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
|
||||
// We expect PEB and TEBs in this dump.
|
||||
EXPECT_TRUE(mini.HasTebs());
|
||||
EXPECT_TRUE(mini.HasPeb());
|
||||
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
|
||||
// We expect no off-stack memory in this dump.
|
||||
EXPECT_FALSE(mini.HasMemory(this));
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, LargerDump) {
|
||||
ASSERT_TRUE(WriteDump(kLargerDumpType));
|
||||
DumpAnalysis mini(dump_file_);
|
||||
|
||||
// The dump should have all of these streams.
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
|
||||
// We expect memory referenced by stack in this dump.
|
||||
EXPECT_TRUE(mini.HasMemory(this));
|
||||
|
||||
// We expect PEB and TEBs in this dump.
|
||||
EXPECT_TRUE(mini.HasTebs());
|
||||
EXPECT_TRUE(mini.HasPeb());
|
||||
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, FullDump) {
|
||||
ASSERT_TRUE(WriteDump(kFullDumpType));
|
||||
ASSERT_TRUE(dump_file_ != L"");
|
||||
ASSERT_TRUE(full_dump_file_ != L"");
|
||||
DumpAnalysis mini(dump_file_);
|
||||
DumpAnalysis full(full_dump_file_);
|
||||
|
||||
// Either dumps can contain part of the information.
|
||||
|
||||
// The dump should have all of these streams.
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(full.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(full.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(full.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(full.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(full.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
EXPECT_TRUE(full.HasStream(MiscInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_TRUE(full.HasStream(HandleDataStream));
|
||||
|
||||
// We expect memory referenced by stack in this dump.
|
||||
EXPECT_FALSE(mini.HasMemory(this));
|
||||
EXPECT_TRUE(full.HasMemory(this));
|
||||
|
||||
// We expect PEB and TEBs in this dump.
|
||||
EXPECT_TRUE(mini.HasTebs() || full.HasTebs());
|
||||
EXPECT_TRUE(mini.HasPeb() || full.HasPeb());
|
||||
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(full.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(full.HasStream(MemoryListStream));
|
||||
|
||||
// This is the only place we don't use OR because we want both not
|
||||
// to have the streams.
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(full.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(full.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(full.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(full.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(full.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(full.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(full.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
EXPECT_FALSE(full.HasStream(TokenStream));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
// Copyright (c) 2010, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#include "../crash_generation/minidump_generator.h"
|
||||
#include "dump_analysis.h" // NOLINT
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Minidump with stacks, PEB, TEB, and unloaded module list.
|
||||
const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
||||
|
||||
// Minidump with all of the above, plus memory referenced from stack.
|
||||
const MINIDUMP_TYPE kLargerDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithUnloadedModules | // Get unloaded modules when available.
|
||||
MiniDumpWithIndirectlyReferencedMemory); // Get memory referenced by stack.
|
||||
|
||||
// Large dump with all process memory.
|
||||
const MINIDUMP_TYPE kFullDumpType = static_cast<MINIDUMP_TYPE>(
|
||||
MiniDumpWithFullMemory | // Full memory from process.
|
||||
MiniDumpWithProcessThreadData | // Get PEB and TEB.
|
||||
MiniDumpWithHandleData | // Get all handle information.
|
||||
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
|
||||
|
||||
class MinidumpTest: public testing::Test {
|
||||
public:
|
||||
MinidumpTest() {
|
||||
wchar_t temp_dir_path[ MAX_PATH ] = {0};
|
||||
::GetTempPath(MAX_PATH, temp_dir_path);
|
||||
dump_path_ = temp_dir_path;
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
// Make sure URLMon isn't loaded into our process.
|
||||
ASSERT_EQ(NULL, ::GetModuleHandle(L"urlmon.dll"));
|
||||
|
||||
// Then load and unload it to ensure we have something to
|
||||
// stock the unloaded module list with.
|
||||
HMODULE urlmon = ::LoadLibrary(L"urlmon.dll");
|
||||
ASSERT_TRUE(urlmon != NULL);
|
||||
ASSERT_TRUE(::FreeLibrary(urlmon));
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
if (!dump_file_.empty()) {
|
||||
::DeleteFile(dump_file_.c_str());
|
||||
dump_file_ = L"";
|
||||
}
|
||||
if (!full_dump_file_.empty()) {
|
||||
::DeleteFile(full_dump_file_.c_str());
|
||||
full_dump_file_ = L"";
|
||||
}
|
||||
}
|
||||
|
||||
bool WriteDump(ULONG flags) {
|
||||
using google_breakpad::MinidumpGenerator;
|
||||
|
||||
// Fake exception is access violation on write to this.
|
||||
EXCEPTION_RECORD ex_record = {
|
||||
STATUS_ACCESS_VIOLATION, // ExceptionCode
|
||||
0, // ExceptionFlags
|
||||
NULL, // ExceptionRecord;
|
||||
reinterpret_cast<void*>(0xCAFEBABE), // ExceptionAddress;
|
||||
2, // NumberParameters;
|
||||
{ EXCEPTION_WRITE_FAULT, reinterpret_cast<ULONG_PTR>(this) }
|
||||
};
|
||||
CONTEXT ctx_record = {};
|
||||
EXCEPTION_POINTERS ex_ptrs = {
|
||||
&ex_record,
|
||||
&ctx_record,
|
||||
};
|
||||
|
||||
MinidumpGenerator generator(dump_path_);
|
||||
|
||||
// And write a dump
|
||||
bool result = generator.WriteMinidump(::GetCurrentProcess(),
|
||||
::GetCurrentProcessId(),
|
||||
::GetCurrentThreadId(),
|
||||
::GetCurrentThreadId(),
|
||||
&ex_ptrs,
|
||||
NULL,
|
||||
static_cast<MINIDUMP_TYPE>(flags),
|
||||
TRUE,
|
||||
&dump_file_,
|
||||
&full_dump_file_);
|
||||
return result == TRUE;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::wstring dump_file_;
|
||||
std::wstring full_dump_file_;
|
||||
|
||||
std::wstring dump_path_;
|
||||
};
|
||||
|
||||
// We need to be able to get file information from Windows
|
||||
bool HasFileInfo(const std::wstring& file_path) {
|
||||
DWORD dummy;
|
||||
const wchar_t* path = file_path.c_str();
|
||||
DWORD length = ::GetFileVersionInfoSize(path, &dummy);
|
||||
if (length == 0)
|
||||
return NULL;
|
||||
|
||||
void* data = calloc(length, 1);
|
||||
if (!data)
|
||||
return false;
|
||||
|
||||
if (!::GetFileVersionInfo(path, dummy, length, data)) {
|
||||
free(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
void* translate = NULL;
|
||||
UINT page_count;
|
||||
BOOL query_result = VerQueryValue(
|
||||
data,
|
||||
L"\\VarFileInfo\\Translation",
|
||||
static_cast<void**>(&translate),
|
||||
&page_count);
|
||||
|
||||
free(data);
|
||||
if (query_result && translate) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, Version) {
|
||||
API_VERSION* version = ::ImagehlpApiVersion();
|
||||
|
||||
HMODULE dbg_help = ::GetModuleHandle(L"dbghelp.dll");
|
||||
ASSERT_TRUE(dbg_help != NULL);
|
||||
|
||||
wchar_t dbg_help_file[1024] = {};
|
||||
ASSERT_TRUE(::GetModuleFileName(dbg_help,
|
||||
dbg_help_file,
|
||||
sizeof(dbg_help_file) /
|
||||
sizeof(*dbg_help_file)));
|
||||
ASSERT_TRUE(HasFileInfo(std::wstring(dbg_help_file)) != NULL);
|
||||
|
||||
// LOG(INFO) << "DbgHelp.dll version: " << file_info->file_version();
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, Normal) {
|
||||
EXPECT_TRUE(WriteDump(MiniDumpNormal));
|
||||
DumpAnalysis mini(dump_file_);
|
||||
|
||||
// We expect threads, modules and some memory.
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
|
||||
// We expect no PEB nor TEBs in this dump.
|
||||
EXPECT_FALSE(mini.HasTebs());
|
||||
EXPECT_FALSE(mini.HasPeb());
|
||||
|
||||
// We expect no off-stack memory in this dump.
|
||||
EXPECT_FALSE(mini.HasMemory(this));
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, SmallDump) {
|
||||
ASSERT_TRUE(WriteDump(kSmallDumpType));
|
||||
DumpAnalysis mini(dump_file_);
|
||||
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
|
||||
// We expect PEB and TEBs in this dump.
|
||||
EXPECT_TRUE(mini.HasTebs());
|
||||
EXPECT_TRUE(mini.HasPeb());
|
||||
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
|
||||
// We expect no off-stack memory in this dump.
|
||||
EXPECT_FALSE(mini.HasMemory(this));
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, LargerDump) {
|
||||
ASSERT_TRUE(WriteDump(kLargerDumpType));
|
||||
DumpAnalysis mini(dump_file_);
|
||||
|
||||
// The dump should have all of these streams.
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
|
||||
// We expect memory referenced by stack in this dump.
|
||||
EXPECT_TRUE(mini.HasMemory(this));
|
||||
|
||||
// We expect PEB and TEBs in this dump.
|
||||
EXPECT_TRUE(mini.HasTebs());
|
||||
EXPECT_TRUE(mini.HasPeb());
|
||||
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
}
|
||||
|
||||
TEST_F(MinidumpTest, FullDump) {
|
||||
ASSERT_TRUE(WriteDump(kFullDumpType));
|
||||
ASSERT_TRUE(dump_file_ != L"");
|
||||
ASSERT_TRUE(full_dump_file_ != L"");
|
||||
DumpAnalysis mini(dump_file_);
|
||||
DumpAnalysis full(full_dump_file_);
|
||||
|
||||
// Either dumps can contain part of the information.
|
||||
|
||||
// The dump should have all of these streams.
|
||||
EXPECT_TRUE(mini.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(full.HasStream(ThreadListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(full.HasStream(ModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(full.HasStream(ExceptionStream));
|
||||
EXPECT_TRUE(mini.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(full.HasStream(SystemInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(full.HasStream(UnloadedModuleListStream));
|
||||
EXPECT_TRUE(mini.HasStream(MiscInfoStream));
|
||||
EXPECT_TRUE(full.HasStream(MiscInfoStream));
|
||||
EXPECT_TRUE(mini.HasStream(HandleDataStream));
|
||||
EXPECT_TRUE(full.HasStream(HandleDataStream));
|
||||
|
||||
// We expect memory referenced by stack in this dump.
|
||||
EXPECT_FALSE(mini.HasMemory(this));
|
||||
EXPECT_TRUE(full.HasMemory(this));
|
||||
|
||||
// We expect PEB and TEBs in this dump.
|
||||
EXPECT_TRUE(mini.HasTebs() || full.HasTebs());
|
||||
EXPECT_TRUE(mini.HasPeb() || full.HasPeb());
|
||||
|
||||
EXPECT_TRUE(mini.HasStream(MemoryListStream));
|
||||
EXPECT_TRUE(full.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(mini.HasStream(Memory64ListStream));
|
||||
EXPECT_FALSE(full.HasStream(MemoryListStream));
|
||||
|
||||
// This is the only place we don't use OR because we want both not
|
||||
// to have the streams.
|
||||
EXPECT_FALSE(mini.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(full.HasStream(ThreadExListStream));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(full.HasStream(CommentStreamA));
|
||||
EXPECT_FALSE(mini.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(full.HasStream(CommentStreamW));
|
||||
EXPECT_FALSE(mini.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(full.HasStream(FunctionTableStream));
|
||||
EXPECT_FALSE(mini.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(full.HasStream(MemoryInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(full.HasStream(ThreadInfoListStream));
|
||||
EXPECT_FALSE(mini.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(full.HasStream(HandleOperationListStream));
|
||||
EXPECT_FALSE(mini.HasStream(TokenStream));
|
||||
EXPECT_FALSE(full.HasStream(TokenStream));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user