From cca33bca9a70fd74a5cec3be1b716059d3710376 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Wed, 13 Jan 2010 20:20:00 -0500 Subject: [PATCH] bug 539552 - make PluginModuleParent write out more data to .extra file. r=bsmedberg --HG-- extra : transplant_source : %C1P%99%80%8E%2C%92%7B%8C%BF%40c%40%FD%18%1F%AE%0E%D8%D9 --- dom/plugins/PluginModuleParent.cpp | 71 +++++++++++++++++++++++++++++- dom/plugins/PluginModuleParent.h | 6 +++ dom/plugins/PluginProcessParent.h | 2 + 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/dom/plugins/PluginModuleParent.cpp b/dom/plugins/PluginModuleParent.cpp index 767cd9a51782..8c9bb923d852 100644 --- a/dom/plugins/PluginModuleParent.cpp +++ b/dom/plugins/PluginModuleParent.cpp @@ -39,6 +39,7 @@ #include "mozilla/plugins/PluginModuleParent.h" #include "mozilla/plugins/BrowserStreamParent.h" +#include "nsCRT.h" #include "nsNPAPIPlugin.h" using mozilla::PluginLibrary; @@ -70,6 +71,7 @@ PluginModuleParent::PluginModuleParent(const char* aFilePath) , mShutdown(false) , mNPNIface(NULL) , mPlugin(NULL) + , mProcessStartTime(time(NULL)) { NS_ASSERTION(mSubprocess, "Out of memory!"); @@ -93,11 +95,76 @@ PluginModuleParent::~PluginModuleParent() } } +void +PluginModuleParent::WriteExtraDataEntry(nsIFileOutputStream* stream, + const char* key, + const char* value) +{ + PRUint32 written; + stream->Write(key, strlen(key), &written); + stream->Write("=", 1, &written); + stream->Write(value, strlen(value), &written); + stream->Write("\n", 1, &written); +} + +void +PluginModuleParent::WriteExtraDataForMinidump(nsIFile* dumpFile) +{ + // get a reference to the extra file, and add some more entries + nsCOMPtr extraFile; + nsresult rv = dumpFile->Clone(getter_AddRefs(extraFile)); + if (NS_FAILED(rv)) + return; + + nsAutoString leafName; + rv = extraFile->GetLeafName(leafName); + if (NS_FAILED(rv)) + return; + + leafName.Replace(leafName.Length() - 3, 3, + NS_LITERAL_STRING("extra")); + rv = extraFile->SetLeafName(leafName); + if (NS_FAILED(rv)) + return; + + nsCOMPtr stream = + do_CreateInstance("@mozilla.org/network/file-output-stream;1"); + // PR_WRONLY | PR_APPEND + rv = stream->Init(extraFile, 0x12, 0600, 0); + if (NS_FAILED(rv)) + return; + WriteExtraDataEntry(stream, "ProcessType", "plugin"); + char startTime[32]; + sprintf(startTime, "%lld", static_cast(mProcessStartTime)); + WriteExtraDataEntry(stream, "StartupTime", startTime); + + // Get the plugin filename, try to get just the file leafname + const std::string& pluginFile = mSubprocess->GetPluginFilePath(); + size_t filePos = pluginFile.rfind(FILE_PATH_SEPARATOR); + if (filePos == std::string::npos) + filePos = 0; + else + filePos++; + WriteExtraDataEntry(stream, "PluginFilename", + pluginFile.substr(filePos).c_str()); + //TODO: add plugin name and version: bug 539841 + // (as PluginName, PluginVersion) + stream->Close(); +} + void PluginModuleParent::ActorDestroy(ActorDestroyReason why) { switch (why) { - case AbnormalShutdown: + case AbnormalShutdown: { + nsCOMPtr dump; + if (GetMinidump(getter_AddRefs(dump))) { + WriteExtraDataForMinidump(dump); + } + else { + NS_WARNING("[PluginModuleParent::ActorDestroy] abnormal shutdown without minidump!"); + } + mShutdown = true; // Defer the PluginCrashed method so that we don't re-enter // and potentially modify the actor child list while enumerating it. @@ -108,7 +175,7 @@ PluginModuleParent::ActorDestroy(ActorDestroyReason why) NS_DispatchToMainThread(r); } break; - + } case NormalShutdown: mShutdown = true; break; diff --git a/dom/plugins/PluginModuleParent.h b/dom/plugins/PluginModuleParent.h index 695c0771cc47..9bd3cb606ea4 100644 --- a/dom/plugins/PluginModuleParent.h +++ b/dom/plugins/PluginModuleParent.h @@ -58,6 +58,7 @@ #include "nsAutoPtr.h" #include "nsTHashtable.h" #include "nsHashKeys.h" +#include "nsIFileStreams.h" namespace mozilla { namespace plugins { @@ -210,11 +211,16 @@ private: char* argv[], NPSavedData* saved, NPError* error); private: + void WriteExtraDataForMinidump(nsIFile* dumpFile); + void WriteExtraDataEntry(nsIFileOutputStream* stream, + const char* key, + const char* value); PluginProcessParent* mSubprocess; bool mShutdown; const NPNetscapeFuncs* mNPNIface; nsTHashtable mValidIdentifiers; nsNPAPIPlugin* mPlugin; + time_t mProcessStartTime; }; } // namespace plugins diff --git a/dom/plugins/PluginProcessParent.h b/dom/plugins/PluginProcessParent.h index c26dc0d85f9a..fad22a4adb83 100644 --- a/dom/plugins/PluginProcessParent.h +++ b/dom/plugins/PluginProcessParent.h @@ -72,6 +72,8 @@ public: return true; } + const std::string& GetPluginFilePath() { return mPluginFilePath; } + using mozilla::ipc::GeckoChildProcessHost::GetShutDownEvent; using mozilla::ipc::GeckoChildProcessHost::GetChannel; using mozilla::ipc::GeckoChildProcessHost::GetChildProcessHandle;