From 14889c340ffe6edeb362232318a8723a96b43a22 Mon Sep 17 00:00:00 2001 From: "ted.mielczarek@gmail.com" Date: Mon, 16 Aug 2010 16:48:59 +0000 Subject: [PATCH] Change ClientInfo into a class to match other platforms, rename the current ClientInfo to ExceptionInfo R=mark at http://breakpad.appspot.com/156001/show git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@651 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/mac/crash_generation/client_info.h | 12 ++++++++---- .../crash_generation/crash_generation_client.cc | 3 +-- .../crash_generation/crash_generation_server.cc | 14 ++++++++------ .../mac/crash_generation/crash_generation_server.h | 7 +++++++ .../mac/tests/crash_generation_server_test.cc | 8 +++++++- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/client/mac/crash_generation/client_info.h b/src/client/mac/crash_generation/client_info.h index 035f5421..a3a95dca 100644 --- a/src/client/mac/crash_generation/client_info.h +++ b/src/client/mac/crash_generation/client_info.h @@ -32,10 +32,14 @@ namespace google_breakpad { -struct ClientInfo { - int exception_type; - int exception_code; - int exception_subcode; +class ClientInfo { + public: + explicit ClientInfo(pid_t pid) : pid_(pid) {} + + pid_t pid() const { return pid_; } + + private: + pid_t pid_; }; } // namespace google_breakpad diff --git a/src/client/mac/crash_generation/crash_generation_client.cc b/src/client/mac/crash_generation/crash_generation_client.cc index 0f21ef17..07428876 100644 --- a/src/client/mac/crash_generation/crash_generation_client.cc +++ b/src/client/mac/crash_generation/crash_generation_client.cc @@ -29,7 +29,6 @@ #include "client/mac/crash_generation/crash_generation_client.h" -#include "client/mac/crash_generation/client_info.h" #include "client/mac/crash_generation/crash_generation_server.h" #include "common/mac/MachIPC.h" @@ -50,7 +49,7 @@ bool CrashGenerationClient::RequestDumpForException( message.AddDescriptor(mach_thread_self()); // handler thread message.AddDescriptor(acknowledge_port.GetPort()); // message receive port - ClientInfo info; + ExceptionInfo info; info.exception_type = exception_type; info.exception_code = exception_code; info.exception_subcode = exception_subcode; diff --git a/src/client/mac/crash_generation/crash_generation_server.cc b/src/client/mac/crash_generation/crash_generation_server.cc index 417dac6a..44548ef0 100644 --- a/src/client/mac/crash_generation/crash_generation_server.cc +++ b/src/client/mac/crash_generation/crash_generation_server.cc @@ -98,12 +98,15 @@ bool CrashGenerationServer::WaitForOneMessage() { if (result == KERN_SUCCESS) { switch (message.GetMessageID()) { case kDumpRequestMessage: { - ClientInfo &info = (ClientInfo &)*message.GetData(); + ExceptionInfo &info = (ExceptionInfo &)*message.GetData(); mach_port_t remote_task = message.GetTranslatedPort(0); mach_port_t crashing_thread = message.GetTranslatedPort(1); mach_port_t handler_thread = message.GetTranslatedPort(2); mach_port_t ack_port = message.GetTranslatedPort(3); + pid_t remote_pid = -1; + pid_for_task(remote_task, &remote_pid); + ClientInfo client(remote_pid); bool result; std::string dump_path; @@ -125,12 +128,12 @@ bool CrashGenerationServer::WaitForOneMessage() { } if (result && dump_callback_) { - dump_callback_(dump_context_, info, dump_path); + dump_callback_(dump_context_, client, dump_path); } // TODO(ted): support a way for the client to send additional data, - // perhaps with a callback so users of the server can read the data - // themselves? + // perhaps with a callback so users of the server can read the data + // themselves? if (ack_port != MACH_PORT_DEAD && ack_port != MACH_PORT_NULL) { MachPortSender sender(ack_port); @@ -141,7 +144,7 @@ bool CrashGenerationServer::WaitForOneMessage() { } if (exit_callback_) { - exit_callback_(exit_context_, info); + exit_callback_(exit_context_, client); } break; } @@ -149,7 +152,6 @@ bool CrashGenerationServer::WaitForOneMessage() { return false; } } else { // result != KERN_SUCCESS - mach_error("WaitForMessage", result); return false; } return true; diff --git a/src/client/mac/crash_generation/crash_generation_server.h b/src/client/mac/crash_generation/crash_generation_server.h index 1f2695c4..e174f9d0 100644 --- a/src/client/mac/crash_generation/crash_generation_server.h +++ b/src/client/mac/crash_generation/crash_generation_server.h @@ -45,6 +45,13 @@ enum { kQuitMessage = 3 }; +// Exception details sent by the client when requesting a dump. +struct ExceptionInfo { + int exception_type; + int exception_code; + int exception_subcode; +}; + class CrashGenerationServer { public: // WARNING: callbacks may be invoked on a different thread diff --git a/src/client/mac/tests/crash_generation_server_test.cc b/src/client/mac/tests/crash_generation_server_test.cc index 6f225337..1ea5bf16 100644 --- a/src/client/mac/tests/crash_generation_server_test.cc +++ b/src/client/mac/tests/crash_generation_server_test.cc @@ -60,6 +60,8 @@ public: char mach_port_name[128]; // Filename of the last dump that was generated string last_dump_name; + // PID of the child process + pid_t child_pid; // A temp dir AutoTempDir temp_dir; // Counter just to ensure that we don't hit the same port again @@ -69,6 +71,7 @@ public: sprintf(mach_port_name, "com.google.breakpad.ServerTest.%d.%d", getpid(), CrashGenerationServerTest::i++); + child_pid = (pid_t)-1; } }; int CrashGenerationServerTest::i = 0; @@ -127,6 +130,7 @@ void dumpCallback(void *context, const ClientInfo &client_info, reinterpret_cast(context); if (!file_path.empty()) self->last_dump_name = file_path; + self->child_pid = client_info.pid(); } } @@ -170,7 +174,9 @@ TEST_F(CrashGenerationServerTest, testRequestDump) { ASSERT_FALSE(last_dump_name.empty()); struct stat st; EXPECT_EQ(0, stat(last_dump_name.c_str(), &st)); - EXPECT_LT(0, st.st_size); + EXPECT_LT(0, st.st_size); + // check client's PID + ASSERT_EQ(pid, child_pid); } static void Crasher() {