Bug 586048. Report graphics device id in crash dumps. r=bsmedberg
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Fri, 27 Aug 2010 11:49:04 -0400
changeset 51579 1c724924c92d1d132d2b00c0a224a827e0122c1e
parent 51578 0866f70e0bd9495d3882a39f52a0068b00ab5752
child 51580 a5a97bafc953463ead28733d769132e0a37ec31d
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs586048
milestone2.0b5pre
Bug 586048. Report graphics device id in crash dumps. r=bsmedberg
widget/src/windows/GfxInfo.cpp
widget/src/windows/GfxInfo.h
--- a/widget/src/windows/GfxInfo.cpp
+++ b/widget/src/windows/GfxInfo.cpp
@@ -37,16 +37,24 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include <windows.h>
 #include "gfxWindowsPlatform.h"
 #include "GfxInfo.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/FunctionTimer.h"
 
+#ifdef MOZ_CRASHREPORTER
+#include "nsExceptionHandler.h"
+#include "nsICrashReporter.h"
+#define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
+#include "nsIPrefService.h"
+#endif
+
+
 using namespace mozilla::widget;
 
 NS_IMPL_ISUPPORTS1(GfxInfo, nsIGfxInfo)
 
 nsresult GfxInfo::GetD2DEnabled(PRBool *aEnabled)
 {
   *aEnabled = gfxWindowsPlatform::GetPlatform()->GetRenderMode() == gfxWindowsPlatform::RENDER_DIRECT2D;
   return NS_OK;
@@ -204,16 +212,19 @@ void GfxInfo::Init()
       }
       RegCloseKey(subkey);
     }
     index++;
     dwcbData = sizeof(subkeyname);
   }
 
   RegCloseKey(key);
+
+
+  AddCrashReportAnnotations();
 }
 
 /* readonly attribute DOMString adapterDescription; */
 NS_IMETHODIMP GfxInfo::GetAdapterDescription(nsAString & aAdapterDescription)
 {
   aAdapterDescription = mDeviceString;
   return NS_OK;
 }
@@ -272,8 +283,35 @@ NS_IMETHODIMP GfxInfo::GetAdapterDeviceI
   if (start != -1) {
     device.Cut(0, start + strlen("&DEV_"));
     device.Truncate(4);
   }
   nsresult err;
   *aAdapterDeviceID = device.ToInteger(&err, 16);
   return NS_OK;
 }
+
+void GfxInfo::AddCrashReportAnnotations()
+{
+#ifdef MOZ_CRASHREPORTER
+  nsCAutoString deviceIDString, vendorIDString;
+  PRUint32 deviceID, vendorID;
+
+  GetAdapterDeviceID(&deviceID);
+  GetAdapterVendorID(&vendorID);
+
+  deviceIDString.AppendPrintf("%04x", &deviceID);
+  vendorIDString.AppendPrintf("%04x", &vendorID);
+
+  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterVendorID"),
+      vendorIDString);
+  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AdapterDeviceID"),
+      deviceIDString);
+
+  /* Add an App Note for now so that we get the data immediately. These
+   * can go away after we store the above in the socorro db */
+  CrashReporter::AppendAppNotesToCrashReport(nsCAutoString(NS_LITERAL_CSTRING("AdapterVendorID: ")) +
+      vendorIDString);
+  CrashReporter::AppendAppNotesToCrashReport(nsCAutoString(NS_LITERAL_CSTRING("AdapterDeviceID: ")) +
+      deviceIDString);
+
+#endif
+}
--- a/widget/src/windows/GfxInfo.h
+++ b/widget/src/windows/GfxInfo.h
@@ -51,16 +51,17 @@ public:
   GfxInfo() {Init();}
   virtual ~GfxInfo() {}
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIGFXINFO
 private:
 
   void Init();
+  void AddCrashReportAnnotations();
   nsString mDeviceString;
   nsString mDeviceID;
   nsString mDriverVersion;
   nsString mDriverDate;
   nsString mDeviceKey;
 };
 
 } // namespace widget