Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass debug messages on to someone else to handle - Windows specific #75

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"variables": {
"BUILD_WITH_LIBEXEC": "<!(python -c 'from ctypes.util import find_library;print int(find_library(\"execinfo\")!=None)')",
"BUILD_WITH_LIBEXEC": "<!(python -c \"from ctypes.util import find_library;print(int(find_library('execinfo')!=None))\")",
},
"targets": [
{
Expand Down
28 changes: 26 additions & 2 deletions src/segfault-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ struct callback_helper {
struct callback_helper* callback;
#endif

#ifdef _WIN32
const DWORD kVCThreadNameException = 0x406D1388;
#endif

char logPath[BUFF_SIZE];

static void buildFileName(char sbuff[BUFF_SIZE], int pid) {
Expand All @@ -192,6 +196,7 @@ static void buildFileName(char sbuff[BUFF_SIZE], int pid) {

SEGFAULT_HANDLER {
long address;
long code;
#ifndef _WIN32
void *array[32]; // Array to store backtrace symbols
size_t size; // To store the size of the stack backtrace
Expand All @@ -208,19 +213,38 @@ SEGFAULT_HANDLER {

#ifdef _WIN32
address = (long)exceptionInfo->ExceptionRecord->ExceptionAddress;
code = (long)exceptionInfo->ExceptionRecord->ExceptionCode;

switch (code) {
case DBG_PRINTEXCEPTION_WIDE_C:
case DBG_PRINTEXCEPTION_C:
// fprintf(stderr, "Debug exception %lx.\n", code);
return EXCEPTION_CONTINUE_SEARCH;
case kVCThreadNameException:
// fprintf(stderr, "Setting thread name %lx.\n", code);
return EXCEPTION_CONTINUE_SEARCH;
default:
break;
}
#else
address = (long)si->si_addr;
code = 0;
#endif

// Write the header line
n = SNPRINTF(
sbuff,
BUFF_SIZE,
"PID %d received SIGSEGV for address: 0x%lx\n",
"PID %d received SIGSEGV for address: 0x%lx code: 0x%lx\n",
pid,
address
address,
code
);

if (code == DBG_PRINTEXCEPTION_C || code == DBG_PRINTEXCEPTION_WIDE_C) {

}

if(fd > 0) {
if (WRITE(fd, sbuff, n) != n) {
fprintf(stderr, "NodeSegfaultHandlerNative: Error writing to file\n");
Expand Down