Address Sanitizer Reports
BugSplat integrates with the Windows Address Sanitizer (Asan) complier option allowing you to capture memory error reports and send them to your BugSplat database. Here are some instructions for modifying myConsoleCrasher (or your application) so that it captures Address Sanitizer exceptions.

Modify Visual Studio Compiler Options

Enable the Address Sanitizer by choosing the Enable Address Sanitizer (/fsanitize=address) C/C++ General option:
Visual Studio Enable Address Sanitizer
Modify the Visual Studio Include Directories so that the Address Sanitizer header files can be located:

Modify Initialization Code

To hook into the Address Sanitizer you will call __asan_set_error_report_callback with the BugSplat createAssanReport method. To do this, we'll need a global instance of the BugSplat MiniDmpSender object and a new asanCallback function. See below for how you would modify our myConsoleCrasher sample program:
1
...
2
#include "sanitizer/asan_interface.h"
3
...
4
โ€‹
5
// Global BugSplat initialization.
6
MiniDmpSender* mpSender = new MiniDmpSender(L"YourDatabase", L"YourAppName", L"YourAppVersion", NULL, MDSF_USEGUARDMEMORY | MDSF_LOGFILE | MDSF_PREVENTHIJACKING);
7
โ€‹
8
void asanCallback(const char* message)
9
{
10
mpSender->createAsanReport(message);
11
}
12
โ€‹
13
int wmain(int argc, wchar_t** argv)
14
{
15
if (IsDebuggerPresent())
16
{
17
exit(0);
18
}
19
โ€‹
20
__asan_set_error_report_callback(asanCallback);
21
22
...
23
}
Copied!

Create Memory Corruption Test

The only step left is to generate a memory corruption that Address Sanitizer will catch. Here's one way to do that:
1
void HeapCorruption() {
2
void* pointerArray[20];
3
struct simple_struct {
4
double b;
5
double c;
6
char d;
7
};
8
โ€‹
9
{
10
auto a = new simple_struct;
11
auto b = new simple_struct;
12
โ€‹
13
pointerArray[0] = a;
14
pointerArray[1] = b;
15
}
16
โ€‹
17
// Function attempts to use pointer from array.
18
// Encounters an error and deletes the pointer without removing it from array
19
{
20
auto item = reinterpret_cast<simple_struct*>(pointerArray[1]);
21
delete item;
22
}
23
โ€‹
24
// Program continues, address is reused
25
constexpr auto numInts = 40;
26
auto intArray = reinterpret_cast<int*>(pointerArray[1]);
27
for (int i = 0; i < numInts; i++) {
28
intArray[i] = 10;
29
}
30
โ€‹
31
// Function called again, encounters the same error and tries to delete the same memory again
32
{
33
auto item = reinterpret_cast<simple_struct*>(pointerArray[1]);
34
โ€‹
35
__try {
36
delete item;
37
}
38
__except (EXCEPTION_EXECUTE_HANDLER) {
39
wprintf(L"exception handling test successful.\n");
40
โ€‹
41
}
42
}
Copied!
Calling HeapCorruption (or your own memory error code) will generate the Address Sanitizer report and send a crash report to BugSplat.

Crash Report Result

You'll see the crash report show up just like other crash exceptions. Here's what our modified version of the myConsoleCrasher sample program produced:
Last modified 4mo ago