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() {