Bug 983022 - [tarako] Need minidump screen shot. r=ted, r=gal
☠☠ backed out by e6531852947f ☠ ☠
authorVincent Liu <vliu@mozilla.com>
Thu, 03 Apr 2014 10:28:07 +0800
changeset 195454 234d50648ad1a3eacaa7eef8f1e14cda825ee6f2
parent 195453 9abb2a6237c19b55d25da07cdd52ac192d1a6dd8
child 195455 5cd9ae69c171d6a71c7f6cb082808880cdf226a6
push idunknown
push userunknown
push dateunknown
reviewersted, gal
bugs983022
milestone31.0a1
Bug 983022 - [tarako] Need minidump screen shot. r=ted, r=gal
dom/ipc/CrashReporterParent.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
--- a/dom/ipc/CrashReporterParent.cpp
+++ b/dom/ipc/CrashReporterParent.cpp
@@ -122,14 +122,16 @@ CrashReporterParent::GenerateChildData(c
     if (!mAppNotes.IsEmpty())
         mNotes.Put(NS_LITERAL_CSTRING("Notes"), mAppNotes);
 
     bool ret = CrashReporter::AppendExtraData(mChildDumpID, mNotes);
     if (ret && processNotes)
         ret = CrashReporter::AppendExtraData(mChildDumpID, *processNotes);
     if (!ret)
         NS_WARNING("problem appending child data to .extra");
+    if (!CrashReporter::WriteScreenShotToFile(mChildDumpID))
+        NS_WARNING("problem writing screen shot to .raw");
     return ret;
 }
 #endif
 
 } // namespace dom
 } // namespace mozilla
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -5,16 +5,17 @@
 
 #include "nsExceptionHandler.h"
 #include "nsDataHashtable.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/CrashReporterChild.h"
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
 #include "mozilla/unused.h"
+#include "mozilla/FileUtils.h"
 
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 
 #if defined(XP_WIN32)
 #ifdef WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
 #endif
@@ -75,16 +76,17 @@ using mozilla::InjectCrashRunnable;
 #include <prmem.h>
 #include "mozilla/Mutex.h"
 #include "nsDebug.h"
 #include "nsCRT.h"
 #include "nsIFile.h"
 #include "prprf.h"
 #include <map>
 #include <vector>
+#include <linux/fb.h>
 
 #include "mozilla/IOInterposer.h"
 #include "mozilla/mozalloc_oom.h"
 #include "mozilla/WindowsDllBlocklist.h"
 
 #if defined(XP_MACOSX)
 CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
 #endif
@@ -2256,16 +2258,48 @@ GetExtraFileForMinidump(nsIFile* minidum
     return false;
 
   *extraFile = nullptr;
   extraF.swap(*extraFile);
   return true;
 }
 
 bool
+WriteScreenShotToFile(const nsAString& id)
+{
+  const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER_DUMP_FB");
+  if (!envvar || !*envvar || !pendingDirectory)
+    return false;
+
+  ScopedClose fb(open("/dev/graphics/fb0", O_RDONLY));
+  if (fb.get() < 0)
+    return false;
+
+  struct fb_fix_screeninfo fi;
+  if (ioctl(fb.get(), FBIOGET_FSCREENINFO, &fi) < 0)
+    return false;
+
+  void* bits = mmap(0, fi.smem_len, PROT_READ, MAP_SHARED, fb.get(), 0);
+  if (MAP_FAILED == bits)
+    return false;
+
+  char path[PATH_MAX];
+  sprintf(path, "%s/%s.raw", pendingDirectory, NS_ConvertUTF16toUTF8(id).get());
+  ScopedClose fd(open(path, O_WRONLY | O_CREAT | O_TRUNC));
+  if (fd.get() < 0) {
+    munmap(bits, fi.smem_len);
+    return false;
+  }
+
+  write(fd.get(), bits, fi.smem_len);
+  munmap(bits, fi.smem_len);
+  return true;
+}
+
+bool
 AppendExtraData(const nsAString& id, const AnnotationTable& data)
 {
   nsCOMPtr<nsIFile> extraFile;
   if (!GetExtraFileForID(id, getter_AddRefs(extraFile)))
     return false;
   return AppendExtraData(extraFile, data);
 }
 
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -75,16 +75,17 @@ nsresult UnregisterAppMemory(void* ptr);
 
 // Functions for working with minidumps and .extras
 typedef nsDataHashtable<nsCStringHashKey, nsCString> AnnotationTable;
 
 bool GetMinidumpForID(const nsAString& id, nsIFile** minidump);
 bool GetIDFromMinidump(nsIFile* minidump, nsAString& id);
 bool GetExtraFileForID(const nsAString& id, nsIFile** extraFile);
 bool GetExtraFileForMinidump(nsIFile* minidump, nsIFile** extraFile);
+bool WriteScreenShotToFile(const nsAString& id);
 bool AppendExtraData(const nsAString& id, const AnnotationTable& data);
 bool AppendExtraData(nsIFile* extraFile, const AnnotationTable& data);
 void RenameAdditionalHangMinidump(nsIFile* minidump, nsIFile* childMinidump,
                                   const nsACString& name);
 
 #ifdef XP_WIN32
   nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo);
 #endif