From 988d69265c9ae88d62a7d63c2c9cc017463ed4e7 Mon Sep 17 00:00:00 2001 From: Vincent Liu Date: Thu, 3 Apr 2014 10:28:07 +0800 Subject: [PATCH] Bug 983022 - [tarako] Need minidump screen shot. r=ted, r=gal --- dom/ipc/CrashReporterParent.cpp | 2 ++ toolkit/crashreporter/nsExceptionHandler.cpp | 34 ++++++++++++++++++++ toolkit/crashreporter/nsExceptionHandler.h | 1 + 3 files changed, 37 insertions(+) diff --git a/dom/ipc/CrashReporterParent.cpp b/dom/ipc/CrashReporterParent.cpp index d38c9fccb53e..cc993c7f9e2b 100644 --- a/dom/ipc/CrashReporterParent.cpp +++ b/dom/ipc/CrashReporterParent.cpp @@ -127,6 +127,8 @@ CrashReporterParent::GenerateChildData(const AnnotationTable* 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 diff --git a/toolkit/crashreporter/nsExceptionHandler.cpp b/toolkit/crashreporter/nsExceptionHandler.cpp index 8be0ffd2ce2b..856ecadbb043 100644 --- a/toolkit/crashreporter/nsExceptionHandler.cpp +++ b/toolkit/crashreporter/nsExceptionHandler.cpp @@ -10,6 +10,7 @@ #include "mozilla/Services.h" #include "nsIObserverService.h" #include "mozilla/unused.h" +#include "mozilla/FileUtils.h" #include "nsThreadUtils.h" #include "nsXULAppAPI.h" @@ -80,6 +81,7 @@ using mozilla::InjectCrashRunnable; #include "prprf.h" #include #include +#include #include "mozilla/IOInterposer.h" #include "mozilla/mozalloc_oom.h" @@ -2260,6 +2262,38 @@ GetExtraFileForMinidump(nsIFile* minidump, nsIFile** 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) { diff --git a/toolkit/crashreporter/nsExceptionHandler.h b/toolkit/crashreporter/nsExceptionHandler.h index cdf97da77ed0..3375364edd84 100644 --- a/toolkit/crashreporter/nsExceptionHandler.h +++ b/toolkit/crashreporter/nsExceptionHandler.h @@ -80,6 +80,7 @@ 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,