mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 662646 - Tests for new crash report API (r=ted)
This commit is contained in:
parent
feabc1b293
commit
33aaa1793d
@ -29,6 +29,9 @@ CrashTestUtils.crash = lib.declare("Crash",
|
||||
ctypes.default_abi,
|
||||
ctypes.void_t,
|
||||
ctypes.int16_t);
|
||||
CrashTestUtils.saveAppMemory = lib.declare("SaveAppMemory",
|
||||
ctypes.default_abi,
|
||||
ctypes.uint64_t);
|
||||
|
||||
CrashTestUtils.lockDir = lib.declare("LockDir",
|
||||
ctypes.default_abi,
|
||||
@ -47,3 +50,8 @@ CrashTestUtils.dumpHasInstructionPointerMemory =
|
||||
ctypes.default_abi,
|
||||
ctypes.bool,
|
||||
ctypes.char.ptr);
|
||||
|
||||
CrashTestUtils.dumpCheckMemory = lib.declare("DumpCheckMemory",
|
||||
ctypes.default_abi,
|
||||
ctypes.bool,
|
||||
ctypes.char.ptr);
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "google_breakpad/processor/minidump.h"
|
||||
#include "nscore.h"
|
||||
|
||||
@ -58,3 +60,48 @@ DumpHasInstructionPointerMemory(const char* dump_file)
|
||||
memory_list->GetMemoryRegionForAddress(instruction_pointer);
|
||||
return region != NULL;
|
||||
}
|
||||
|
||||
// This function tests for a very specific condition. It finds
|
||||
// an address in a file, "crash-addr", in the CWD. It checks
|
||||
// that the minidump has a memory region starting at that
|
||||
// address. The region must be 32 bytes long and contain the
|
||||
// values 0 to 31 as bytes, in ascending order.
|
||||
extern "C"
|
||||
NS_EXPORT bool
|
||||
DumpCheckMemory(const char* dump_file)
|
||||
{
|
||||
Minidump dump(dump_file);
|
||||
if (!dump.Read())
|
||||
return false;
|
||||
|
||||
MinidumpMemoryList* memory_list = dump.GetMemoryList();
|
||||
if (!memory_list) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void *addr;
|
||||
FILE *fp = fopen("crash-addr", "r");
|
||||
if (!fp)
|
||||
return false;
|
||||
if (fscanf(fp, "%p", &addr) != 1)
|
||||
return false;
|
||||
fclose(fp);
|
||||
|
||||
remove("crash-addr");
|
||||
|
||||
MinidumpMemoryRegion* region =
|
||||
memory_list->GetMemoryRegionForAddress(u_int64_t(addr));
|
||||
if(!region)
|
||||
return false;
|
||||
|
||||
const u_int8_t* chars = region->GetMemory();
|
||||
if (region->GetSize() != 32)
|
||||
return false;
|
||||
|
||||
for (int i=0; i<32; i++) {
|
||||
if (chars[i] != i)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsExceptionHandler.h"
|
||||
|
||||
/*
|
||||
* This pure virtual call example is from MSDN
|
||||
@ -67,3 +70,20 @@ nsISupports* LockDir(nsILocalFile *directory)
|
||||
XRE_LockProfileDirectory(directory, &lockfile);
|
||||
return lockfile;
|
||||
}
|
||||
|
||||
char testData[32];
|
||||
|
||||
extern "C" NS_EXPORT
|
||||
PRUint64 SaveAppMemory()
|
||||
{
|
||||
for (size_t i=0; i<sizeof(testData); i++)
|
||||
testData[i] = i;
|
||||
|
||||
FILE *fp = fopen("crash-addr", "w");
|
||||
if (!fp)
|
||||
return 0;
|
||||
fprintf(fp, "%p\n", (void *)testData);
|
||||
fclose(fp);
|
||||
|
||||
return (PRInt64)testData;
|
||||
}
|
||||
|
12
toolkit/crashreporter/test/unit/test_crashreporter_appmem.js
Normal file
12
toolkit/crashreporter/test/unit/test_crashreporter_appmem.js
Normal file
@ -0,0 +1,12 @@
|
||||
function run_test()
|
||||
{
|
||||
do_crash(function() {
|
||||
appAddr = CrashTestUtils.saveAppMemory();
|
||||
crashReporter.registerAppMemory(appAddr, 32);
|
||||
},
|
||||
function(mdump, extra) {
|
||||
do_check_true(mdump.exists());
|
||||
do_check_true(mdump.fileSize > 0);
|
||||
do_check_true(CrashTestUtils.dumpCheckMemory(mdump.path));
|
||||
});
|
||||
}
|
@ -7,3 +7,6 @@ tail =
|
||||
[test_crashreporter.js]
|
||||
[test_crashreporter_crash.js]
|
||||
[test_crashreporter_crash_profile_lock.js]
|
||||
|
||||
[test_crashreporter_appmem.js]
|
||||
run-if = os == 'win' || os == 'linux'
|
||||
|
@ -972,6 +972,13 @@ nsXULAppInfo::AppendAppNotesToCrashReport(const nsACString& data)
|
||||
return CrashReporter::AppendAppNotesToCrashReport(data);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULAppInfo::RegisterAppMemory(PRUint64 pointer,
|
||||
PRUint64 len)
|
||||
{
|
||||
return CrashReporter::RegisterAppMemory((void *)pointer, len);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULAppInfo::WriteMinidumpForException(void* aExceptionInfo)
|
||||
{
|
||||
|
@ -102,6 +102,19 @@ interface nsICrashReporter : nsISupports
|
||||
*/
|
||||
void appendAppNotesToCrashReport(in ACString data);
|
||||
|
||||
/**
|
||||
* Register a given memory range to be included in the crash report.
|
||||
*
|
||||
* @param ptr
|
||||
* The starting address for the bytes.
|
||||
* @param size
|
||||
* The number of bytes to include.
|
||||
*
|
||||
* @throw NS_ERROR_NOT_INITIALIZED if crash reporting not initialized
|
||||
* @throw NS_ERROR_NOT_IMPLEMENTED if unavailable on the current OS
|
||||
*/
|
||||
void registerAppMemory(in unsigned long long ptr, in unsigned long long size);
|
||||
|
||||
/**
|
||||
* Write a minidump immediately, with the user-supplied exception
|
||||
* information. This is implemented on Windows only, because
|
||||
|
Loading…
Reference in New Issue
Block a user